S7 1200 Programmable Controller S71200 System Manual En US
User Manual: Pdf
Open the PDF directly: View PDF
.
Page Count: 1614
| Download | |
| Open PDF In Browser | View PDF |
S7-1200 Programmable controller
SIMATIC
S7
S7-1200 Programmable controller
System Manual
V4.2, 09/2016
A5E02486680-AK
___________________
Preface
1
___________________
Product overview
2
___________________
New features
STEP 7 programming
3
___________________
software
4
___________________
Installation
___________________
5
PLC concepts
___________________
6
Device configuration
___________________
7
Programming concepts
___________________
8
Basic instructions
___________________
9
Extended instructions
___________________
10
Technology instructions
___________________
11
Communication
___________________
12
Web server
Communication processor
___________________
13
and Modbus TCP
TeleService communication
___________________
14
(SMTP email)
___________________
15
Online and diagnostic tools
___________________
A
Technical specifications
___________________
B
Calculating a power budget
___________________
C
Ordering Information
Device exchange and spare
___________________
D
parts compatibility
Legal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent
damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert
symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are
graded according to the degree of danger.
DANGER
indicates that death or severe personal injury will result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury may result if proper precautions are not taken.
CAUTION
indicates that minor personal injury can result if proper precautions are not taken.
NOTICE
indicates that property damage can result if proper precautions are not taken.
If more than one degree of danger is present, the warning notice representing the highest degree of danger will
be used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to
property damage.
Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific
task in accordance with the relevant documentation, in particular its warning notices and safety instructions.
Qualified personnel are those who, based on their training and experience, are capable of identifying risks and
avoiding potential hazards when working with these products/systems.
Proper use of Siemens products
Note the following:
WARNING
Siemens products may only be used for the applications described in the catalog and in the relevant technical
documentation. If products and components from other manufacturers are used, these must be recommended
or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and
maintenance are required to ensure that the products operate safely and without any problems. The permissible
ambient conditions must be complied with. The information in the relevant documentation must be observed.
Trademarks
All names identified by ® are registered trademarks of Siemens AG. The remaining trademarks in this publication
may be trademarks whose use by third parties for their own purposes could violate the rights of the owner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software
described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the
information in this publication is reviewed regularly and any necessary corrections are included in subsequent
editions.
Siemens AG
Division Digital Factory
Postfach 48 48
90026 NÜRNBERG
GERMANY
A5E02486680-AK
Ⓟ 08/2016 Subject to change
Copyright © Siemens AG 2016.
All rights reserved
Preface
Purpose of the manual
The S7-1200 series is a line of programmable logic controllers (PLCs) that can control a
variety of automation applications. Compact design, low cost, and a powerful instruction set
make the S7-1200 a perfect solution for controlling a wide variety of applications. The S71200 models and the Windows-based STEP 7 programming tool (Page 37) give you the
flexibility you need to solve your automation problems.
This manual provides information about installing and programming the S7-1200 PLCs and
is designed for engineers, programmers, installers, and electricians who have a general
knowledge of programmable logic controllers.
Required basic knowledge
To understand this manual, it is necessary to have a general knowledge of automation and
programmable logic controllers.
Scope of the manual
This manual describes the following products:
● STEP 7 V14 Basic and Professional (Page 37)
● S7-1200 CPU firmware release V4.2
For a complete list of the S7-1200 products described in this manual, refer to the technical
specifications (Page 1359).
Certification, CE label, C-Tick, and other approvals
Refer to the technical specifications (Page 1359) for more information.
Service and support
In addition to our documentation, Siemens offers technical expertise on the Internet and on
the customer support web site (http://support.industry.siemens.com).
Contact your Siemens distributor or sales office for assistance in answering any technical
questions, for training, or for ordering S7 products. Because your sales representatives are
technically trained and have the most specific knowledge about your operations, process
and industry, as well as about the individual Siemens products that you are using, they can
provide the fastest and most efficient answers to any problems you might encounter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
3
Preface
Documentation and information
S7-1200 and STEP 7 provide a variety of documentation and other resources for finding the
technical information that you require.
● The S7-1200 Programmable Controller System Manual provides specific information
about the operation, programming, and the specifications for the complete S7-1200
product family. In addition to the system manual, the S7-1200 Easy Book provides a
more general overview to the capabilities of the S7-1200 family.
Both the system manual and the Easy Book are available as electronic (PDF) manuals.
You can download or view the electronic manuals from the Siemens Industry Online
Support Web site (http://support.industry.siemens.com). The system manual is also
available on the Documents Disk that ships with every S7-1200 CPU.
● The online STEP 7 information system provides immediate access to the conceptual
information and specific instructions that describe the operation and functionality of the
programming package and basic operation of SIMATIC CPUs.
● The Siemens Industry Online Support Web site (http://support.industry.siemens.com)
provides access to the electronic (PDF) versions of the SIMATIC documentation set,
including the system manual, the Easy Book, and the STEP 7 information system.
Existing documents are available from the Product Support link. With this online
documentation access, you can also drag and drop topics from various documents to
create your own custom manual.
You can access online documentation by clicking "mySupport" from the left side of the
page and selecting "Documentation" from the navigation choices. To use the mySupport
Documentation features, you must sign up as a registered user.
● The Update to the S7-1200 System Manual, edition 07/2016
(https://support.industry.siemens.com/cs/ww/en/view/108168658) has updates to the S71200 Programmable Controller System Manual that occurred after publication.
● The Siemens Industry Online Support Web site also provides FAQs and other helpful
documents for S7-1200 and STEP 7.
● You can also follow or join product discussions on the Service & Support technical forum
(https://support.industry.siemens.com/tf/ww/en/?Language=en&siteid=csius&treeLang=e
n&groupid=4000002&extranet=standard&viewreg=WW&nodeid0=34612486). These
forums allow you to interact with various product experts.
– Forum for S7-1200
(https://support.industry.siemens.com/tf/ww/en/threads/237?title=simatic-s71200&skip=0&take=10&orderBy=LastPostDate+desc)
– Forum for STEP 7 Basic
(https://support.industry.siemens.com/tf/ww/en/threads/243?title=step-7-tiaportal&skip=0&take=10&orderBy=LastPostDate+desc)
S7-1200 Programmable controller
4
System Manual, V4.2, 09/2016, A5E02486680-AK
Preface
Security information
Siemens provides products and solutions with industrial security functions that support the
secure operation of plants, systems, machines and networks.
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.industry.siemens.com/topics/global/en/industrial-security/Pages/default.aspx).
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 customer’s exposure to cyber threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security RSS
Feed under (https://support.industry.siemens.com/cs/us/en/).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
5
Preface
S7-1200 Programmable controller
6
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
Preface ................................................................................................................................................... 3
1
Product overview .................................................................................................................................. 27
1.1
Introducing the S7-1200 PLC .................................................................................................27
1.2
Expansion capability of the CPU ............................................................................................30
1.3
Basic HMI panels ....................................................................................................................32
2
New features......................................................................................................................................... 33
3
STEP 7 programming software ............................................................................................................. 37
4
3.1
System requirements ..............................................................................................................38
3.2
Different views to make the work easier .................................................................................39
3.3
3.3.1
3.3.2
3.3.3
3.3.4
3.3.5
3.3.6
3.3.7
3.3.8
3.3.9
3.3.10
3.3.11
3.3.12
Easy-to-use tools ....................................................................................................................41
Inserting instructions into your user program .........................................................................41
Accessing instructions from the "Favorites" toolbar ...............................................................41
Creating a complex equation with a simple instruction...........................................................42
Adding inputs or outputs to a LAD or FBD instruction ............................................................44
Expandable instructions ..........................................................................................................44
Selecting a version for an instruction ......................................................................................45
Modifying the appearance and configuration of STEP 7 ........................................................45
Dragging and dropping between editors .................................................................................46
Changing the operating mode of the CPU ..............................................................................47
Changing the call type for a DB ..............................................................................................48
Temporarily disconnecting devices from a network ................................................................49
Virtual unplugging of devices from the configuration ..............................................................50
3.4
Backward compatibility ...........................................................................................................51
Installation ............................................................................................................................................ 53
4.1
Guidelines for installing S7-1200 devices ...............................................................................53
4.2
Power budget ..........................................................................................................................56
4.3
4.3.1
4.3.2
4.3.3
4.3.4
4.3.5
4.3.6
4.3.7
4.3.8
4.3.8.1
4.3.8.2
4.3.8.3
4.3.8.4
Installation and removal procedures .......................................................................................57
Mounting dimensions for the S7-1200 devices .......................................................................57
Installing and removing the CPU ............................................................................................61
Installing and removing an SB, CB, or BB ..............................................................................63
Installing and removing an SM ...............................................................................................65
Installing and removing a CM or CP .......................................................................................67
Removing and reinstalling the S7-1200 terminal block connector .........................................68
Installing and removing the expansion cable ..........................................................................69
TS (TeleService) adapter ........................................................................................................71
Connecting the TeleService adapter ......................................................................................71
Installing the SIM card ............................................................................................................73
Installing the TS adapter unit on a DIN rail .............................................................................74
Installing the TS adapter on a panel .......................................................................................75
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
7
Table of contents
4.4
5
Wiring guidelines .................................................................................................................... 76
PLC concepts ....................................................................................................................................... 83
5.1
5.1.1
5.1.2
5.1.3
5.1.3.1
5.1.3.2
5.1.3.3
5.1.3.4
5.1.3.5
5.1.3.6
5.1.3.7
5.1.3.8
5.1.3.9
5.1.3.10
5.1.3.11
5.1.3.12
5.1.3.13
5.1.3.14
5.1.3.15
5.1.3.16
5.1.3.17
5.1.4
5.1.5
5.1.5.1
5.1.6
5.1.7
5.1.8
Execution of the user program ............................................................................................... 83
Operating modes of the CPU ................................................................................................. 87
Processing the scan cycle in RUN mode ............................................................................... 91
Organization blocks (OBs) ..................................................................................................... 92
Program cycle OB .................................................................................................................. 92
Startup OB ............................................................................................................................. 93
Time delay interrupt OB ......................................................................................................... 93
Cyclic interrupt OB ................................................................................................................. 94
Hardware interrupt OB ........................................................................................................... 95
Time error interrupt OB .......................................................................................................... 96
Diagnostic error interrupt OB ................................................................................................. 97
Pull or plug of modules OB .................................................................................................. 100
Rack or station failure OB .................................................................................................... 101
Time of day OB .................................................................................................................... 102
Status OB ............................................................................................................................. 102
Update OB ........................................................................................................................... 103
Profile OB ............................................................................................................................. 103
MC-Servo and MC-Interpolator OB...................................................................................... 103
MC-PreServo ....................................................................................................................... 104
MC-PostServo ...................................................................................................................... 105
Event execution priorities and queuing ................................................................................ 105
Monitoring and configuring the cycle time ........................................................................... 109
CPU memory........................................................................................................................ 110
System and clock memory ................................................................................................... 112
Diagnostics buffer ................................................................................................................ 114
Time of day clock ................................................................................................................. 115
Configuring the outputs on a RUN-to-STOP transition ........................................................ 116
5.2
5.2.1
Data storage, memory areas, I/O and addressing ............................................................... 117
Accessing the data of the S7-1200 ...................................................................................... 117
5.3
Processing of analog values ................................................................................................ 123
5.4
5.4.1
5.4.2
5.4.3
5.4.4
5.4.5
5.4.6
5.4.7
5.4.8
5.4.9
5.4.10
5.4.11
Data types ............................................................................................................................ 125
Bool, Byte, Word, and DWord data types ............................................................................ 126
Integer data types ................................................................................................................ 127
Floating-point real data types............................................................................................... 127
Time and Date data types .................................................................................................... 128
Character and String data types .......................................................................................... 130
Array data type ..................................................................................................................... 132
Data structure data type ....................................................................................................... 133
PLC data type ...................................................................................................................... 133
Variant pointer data type ...................................................................................................... 134
Accessing a "slice" of a tagged data type ............................................................................ 134
Accessing a tag with an AT overlay ..................................................................................... 135
5.5
5.5.1
5.5.2
Using a memory card ........................................................................................................... 138
Inserting a memory card in the CPU .................................................................................... 139
Configuring the startup parameter of the CPU before copying the project to the
memory card ........................................................................................................................ 142
Transfer card ........................................................................................................................ 142
5.5.3
S7-1200 Programmable controller
8
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
6
7
5.5.4
5.5.5
Program card ........................................................................................................................145
Firmware update ...................................................................................................................148
5.6
Recovery from a lost password ............................................................................................151
Device configuration............................................................................................................................ 153
6.1
Inserting a CPU .....................................................................................................................154
6.2
Uploading the configuration of a connected CPU .................................................................156
6.3
Adding modules to the configuration ....................................................................................158
6.4
6.4.1
6.4.2
6.4.3
Configuration control .............................................................................................................159
Advantages and applications of configuration control ..........................................................159
Configuring the central installation and optional modules ....................................................159
Example of configuration control ..........................................................................................166
6.5
Changing a device ................................................................................................................170
6.6
6.6.1
6.6.2
6.6.3
Configuring the operation of the CPU ...................................................................................170
Overview ...............................................................................................................................170
Configuring digital input filter times .......................................................................................172
Pulse catch ...........................................................................................................................174
6.7
Configuring multilingual support ...........................................................................................175
6.8
Configuring the parameters of the modules .........................................................................177
6.9
Configuring the CPU for communication ..............................................................................179
6.10
Time synchronization ............................................................................................................181
Programming concepts ....................................................................................................................... 183
7.1
Guidelines for designing a PLC system ................................................................................183
7.2
Structuring your user program ..............................................................................................185
7.3
7.3.1
7.3.2
7.3.3
7.3.4
7.3.5
7.3.6
Using blocks to structure your program ................................................................................187
Organization block (OB)........................................................................................................188
Function (FC) ........................................................................................................................190
Function block (FB) ...............................................................................................................190
Data block (DB) .....................................................................................................................192
Creating reusable code blocks .............................................................................................194
Passing parameters to blocks...............................................................................................195
7.4
Understanding data consistency ...........................................................................................198
7.5
7.5.1
7.5.2
7.5.3
7.5.3.1
7.5.3.2
7.5.3.3
7.5.4
Programming language.........................................................................................................199
Ladder logic (LAD) ................................................................................................................199
Function Block Diagram (FBD) .............................................................................................200
SCL .......................................................................................................................................201
SCL program editor ...............................................................................................................201
SCL expressions and operations ..........................................................................................202
Indexed addressing with PEEK and POKE instructions .......................................................206
EN and ENO for LAD, FBD and SCL ....................................................................................208
7.6
7.6.1
7.6.2
7.6.3
Protection ..............................................................................................................................210
Access protection for the CPU ..............................................................................................210
External load memory ...........................................................................................................212
Know-how protection ............................................................................................................213
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
9
Table of contents
8
7.6.4
Copy protection .................................................................................................................... 214
7.7
Downloading the elements of your program ........................................................................ 216
7.8
Synchronizing the online CPU and offline project................................................................ 219
7.9
7.9.1
Uploading from the online CPU ........................................................................................... 221
Comparing the online CPU to the offline CPU ..................................................................... 221
7.10
7.10.1
7.10.2
7.10.3
7.10.4
Debugging and testing the program..................................................................................... 222
Monitor and modify data in the CPU .................................................................................... 222
Watch tables and force tables.............................................................................................. 223
Cross reference to show usage ........................................................................................... 223
Call structure to examine the calling hierarchy .................................................................... 225
Basic instructions .................................................................................................................................227
8.1
8.1.1
8.1.2
8.1.3
Bit logic operations ............................................................................................................... 227
Bit logic instructions ............................................................................................................. 227
Set and reset instructions .................................................................................................... 230
Positive and negative edge instructions .............................................................................. 233
8.2
Timer operations .................................................................................................................. 236
8.3
Counter operations .............................................................................................................. 244
8.4
8.4.1
8.4.2
8.4.3
8.4.4
8.4.4.1
8.4.4.2
8.4.4.3
Comparator operations ........................................................................................................ 250
Compare values instructions................................................................................................ 250
IN_Range (Value within range) and OUT_Range (Value outside range) ............................ 251
OK (Check validity) and NOT_OK (Check invalidity) ........................................................... 252
Variant and array comparison instructions .......................................................................... 253
Equality and non-equality comparison instructions.............................................................. 253
Null comparsion instructions ................................................................................................ 254
IS_ARRAY (Check for ARRAY) ........................................................................................... 254
8.5
8.5.1
8.5.2
8.5.3
8.5.4
8.5.5
8.5.6
8.5.7
8.5.8
8.5.9
Math functions ...................................................................................................................... 255
CALCULATE (Calculate) ..................................................................................................... 255
Add, subtract, multiply and divide instructions ..................................................................... 257
MOD (return remainder of division)...................................................................................... 258
NEG (Create twos complement) .......................................................................................... 259
INC (Increment) and DEC (Decrement) ............................................................................... 259
ABS (Form absolute value) .................................................................................................. 260
MIN (Get minimum) and MAX (Get maximum) .................................................................... 261
LIMIT (Set limit value) .......................................................................................................... 262
Exponent, logarithm, and trigonometry instructions............................................................. 263
8.6
8.6.1
Move operations................................................................................................................... 265
MOVE (Move value), MOVE_BLK (Move block), UMOVE_BLK (Move block
uninterruptible), and MOVE_BLK_VARIANT (Move block) ................................................. 265
Deserialize ........................................................................................................................... 269
Serialize ............................................................................................................................... 272
FILL_BLK (Fill block) and UFILL_BLK (Fill block uninterruptible) ........................................ 275
SWAP (Swap bytes) ............................................................................................................ 276
LOWER_BOUND: (Read out ARRAY low limit) ................................................................... 277
UPPER_BOUND: (Read out ARRAY high limit) .................................................................. 279
Read / Write memory instructions ........................................................................................ 281
PEEK and POKE (SCL only) ............................................................................................... 281
Read and write big and little Endian instructions (SCL)....................................................... 283
8.6.2
8.6.3
8.6.4
8.6.5
8.6.6
8.6.7
8.6.8
8.6.8.1
8.6.8.2
S7-1200 Programmable controller
10
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
8.6.9
8.6.9.1
8.6.9.2
8.6.9.3
8.6.10
8.6.10.1
Variant instructions ...............................................................................................................285
VariantGet (Read VARIANT tag value) ................................................................................285
VariantPut (Write VARIANT tag value) .................................................................................286
CountOfElements (Get number of ARRAY elements) ..........................................................287
Legacy instructions ...............................................................................................................288
FieldRead (Read field) and FieldWrite (Write field) instructions ...........................................288
8.7
8.7.1
8.7.2
8.7.3
8.7.4
8.7.5
8.7.6
8.7.6.1
8.7.6.2
Conversion operations ..........................................................................................................290
CONV (Convert value) ..........................................................................................................290
Conversion instructions for SCL ...........................................................................................291
ROUND (Round numerical value) and TRUNC (Truncate numerical value) ........................294
CEIL and FLOOR (Generate next higher and lower integer from floating-point number) ....295
SCALE_X (Scale) and NORM_X (Normalize) ......................................................................296
Variant conversion instructions .............................................................................................299
VARIANT_TO_DB_ANY (Convert VARIANT to DB_ANY) ...................................................299
DB_ANY_TO_VARIANT (Convert DB_ANY to VARIANT) ...................................................300
8.8
8.8.1
8.8.2
8.8.3
8.8.4
8.8.5
8.8.6
8.8.7
8.8.8
8.8.9
8.8.10
8.8.10.1
8.8.10.2
8.8.10.3
8.8.10.4
8.8.10.5
8.8.10.6
8.8.10.7
8.8.10.8
8.8.10.9
8.8.10.10
Program control operations ..................................................................................................302
JMP (Jump if RLO = 1), JMPN (Jump if RLO = 0), and Label (Jump label) instructions .....302
JMP_LIST (Define jump list) .................................................................................................303
SWITCH (Jump distributor) ...................................................................................................304
RET (Return) .........................................................................................................................306
ENDIS_PW (Enable/disable CPU passwords) .....................................................................307
RE_TRIGR (Restart cycle monitoring time) ..........................................................................309
STP (Exit program) ...............................................................................................................310
GET_ERROR and GET_ERROR_ID (Get error and error ID locally) instructions ...............311
RUNTIME (Measure program runtime) .................................................................................314
SCL program control statements ..........................................................................................316
Overview of SCL program control statements ......................................................................316
IF-THEN statement ...............................................................................................................317
CASE statement ...................................................................................................................318
FOR statement ......................................................................................................................320
WHILE-DO statement ...........................................................................................................321
REPEAT-UNTIL statement ...................................................................................................322
CONTINUE statement ..........................................................................................................323
EXIT statement .....................................................................................................................324
GOTO statement ...................................................................................................................325
RETURN statement ..............................................................................................................325
8.9
8.9.1
8.9.2
8.9.3
8.9.4
Word logic operations ...........................................................................................................326
AND, OR, and XOR logic operation instructions ..................................................................326
INV (Create ones complement) ............................................................................................327
DECO (Decode) and ENCO (Encode) instructions ..............................................................327
SEL (Select), MUX (Multiplex), and DEMUX (Demultiplex) instructions ..............................329
8.10
8.10.1
8.10.2
Shift and rotate ......................................................................................................................332
SHR (Shift right) and SHL (Shift left) instructions .................................................................332
ROR (Rotate right) and ROL (Rotate left) instructions .........................................................333
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
11
Table of contents
9
Extended instructions ...........................................................................................................................335
9.1
9.1.1
9.1.2
9.1.3
9.1.4
9.1.5
Date, time-of-day, and clock functions ................................................................................. 335
Date and time-of-day instructions ........................................................................................ 335
Clock functions ..................................................................................................................... 338
TimeTransformationRule data structure .............................................................................. 342
SET_TIMEZONE (Set timezone) ......................................................................................... 343
RTM (Runtime meters) ........................................................................................................ 344
9.2
9.2.1
9.2.2
9.2.3
9.2.3.1
9.2.3.3
9.2.4
9.2.4.1
9.2.4.2
9.2.4.3
9.2.4.4
9.2.4.5
9.2.4.6
9.2.4.7
9.2.4.8
9.2.5
9.2.5.1
9.2.5.2
9.2.5.3
9.2.5.4
9.2.5.5
String and character ............................................................................................................. 346
String data overview ............................................................................................................ 346
S_MOVE (Move character string) ........................................................................................ 346
String conversion instructions .............................................................................................. 347
S_CONV, STRG_VAL, and VAL_STRG (Convert to/from character string and number)
instructions ........................................................................................................................... 347
Strg_TO_Chars and Chars_TO_Strg (Convert to/from character string and array of
CHAR) instructions .............................................................................................................. 357
ATH and HTA (Convert to/from ASCII string and hexadecimal number) instructions ......... 359
String operation instructions ................................................................................................ 361
MAX_LEN (Maximum length of a character string).............................................................. 361
LEN (Determine the length of a character string) ................................................................ 362
CONCAT (Combine character strings) ................................................................................ 363
LEFT, RIGHT, and MID (Read substrings in a character string) instructions ...................... 364
DELETE (Delete characters in a character string)............................................................... 365
INSERT (Insert characters in a character string) ................................................................. 366
REPLACE (Replace characters in a character string) ......................................................... 367
FIND (Find characters in a character string) ........................................................................ 369
Runtime information ............................................................................................................. 370
GetSymbolName (Read out a tag on the input parameter) ................................................. 370
GetSymbolPath (Query composite global name of the input parameter assignment) ........ 373
GetInstanceName (Read out name of the block instance) .................................................. 376
GetInstancePath (Query composite global name of the block instance) ............................. 379
GetBlockName (Read out name of the block) ..................................................................... 381
9.3
9.3.1
9.3.2
9.3.3
9.3.4
9.3.5
9.3.6
9.3.7
9.3.8
9.3.9
9.3.10
9.3.10.1
9.3.10.2
9.3.10.3
9.3.10.4
Distributed I/O (PROFINET, PROFIBUS, or AS-i) ............................................................... 384
Distributed I/O Instructions ................................................................................................... 384
RDREC and WRREC (Read/write data record) ................................................................... 385
GETIO (Read process image) ............................................................................................. 388
SETIO (Transfer process image) ......................................................................................... 389
GETIO_PART (Read process image area) .......................................................................... 390
SETIO_PART (Transfer process image area) ..................................................................... 392
RALRM (Receive interrupt) .................................................................................................. 394
D_ACT_DP (Enable/disable PROFINET IO devices) .......................................................... 398
STATUS parameter for RDREC, WRREC, and RALRM ..................................................... 403
Others .................................................................................................................................. 408
DPRD_DAT and DPWR_DAT (Read/write consistent data) ................................................ 408
RCVREC (I-device/I-slave receive data record) .................................................................. 411
PRVREC (I-device/I-slave make data record available) ...................................................... 413
DPNRM_DG (Read diagnostic data from a PROFIBUS DP slave) ..................................... 416
9.4
PROFIenergy ....................................................................................................................... 419
9.5
9.5.1
9.5.2
Interrupts .............................................................................................................................. 420
ATTACH and DETACH (Attach/detach an OB and an interrupt event) instructions ........... 420
Cyclic interrupts.................................................................................................................... 424
9.2.3.2
S7-1200 Programmable controller
12
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
9.5.2.1
9.5.2.2
9.5.3
9.5.3.1
9.5.3.2
9.5.3.3
9.5.3.4
9.5.4
9.5.5
SET_CINT (Set cyclic interrupt parameters).........................................................................424
QRY_CINT (Query cyclic interrupt parameters) ...................................................................426
Time of day interrupts ...........................................................................................................427
SET_TINTL (Set time of day interrupt) .................................................................................428
CAN_TINT (Cancel time of day interrupt) .............................................................................429
ACT_TINT (Activate time of day interrupt) ............................................................................430
QRY_TINT (Query status of time of day interrupt) ...............................................................431
Time delay interrupts ............................................................................................................432
DIS_AIRT and EN_AIRT (Delay/enable execution of higher priority interrupts and
asynchronous error events) instructions ...............................................................................435
9.6
9.6.1
Alarms ...................................................................................................................................436
Gen_UsrMsg (Generate user diagnostic alarms) .................................................................436
9.7
9.7.1
9.7.2
9.7.3
9.7.4
9.7.5
9.7.6
9.7.7
9.7.7.1
9.7.8
9.7.8.1
9.7.9
9.7.10
Diagnostics (PROFINET or PROFIBUS) ..............................................................................439
Diagnostic instructions ..........................................................................................................439
RD_SINFO (Read current OB start information) ..................................................................440
LED (Read LED status) ........................................................................................................450
Get_IM_Data (Read the identification and maintenance data) .............................................451
Get_Name (Read the name of a PROFINET IO device) ......................................................453
GetStationInfo (Read the IP or MAC address of a PROFINET IO device)...........................460
DeviceStates instruction .......................................................................................................468
DeviceStates example configurations...................................................................................469
ModuleStates instruction ......................................................................................................474
ModuleStates example configurations ..................................................................................476
GET_DIAG (Read diagnostic information) ............................................................................480
Diagnostic events for distributed I/O .....................................................................................486
9.8
9.8.1
9.8.2
9.8.3
9.8.4
Pulse .....................................................................................................................................487
CTRL_PWM (Pulse width modulation) .................................................................................487
CTRL_PTO (Pulse train output) ............................................................................................488
Operation of the pulse outputs ..............................................................................................492
Configuring a pulse channel for PWM or PTO .....................................................................494
9.9
9.9.1
9.9.1.1
9.9.1.2
9.9.1.3
9.9.1.4
9.9.2
9.9.2.1
9.9.2.2
9.9.2.3
9.9.2.4
9.9.2.5
Recipes and Data logs ..........................................................................................................498
Recipes .................................................................................................................................498
Recipe overview ....................................................................................................................498
Recipe example ....................................................................................................................499
Program instructions that transfer recipe data ......................................................................502
Recipe example program ......................................................................................................506
Data logs ...............................................................................................................................509
Data log record structure ......................................................................................................509
Program instructions that control data logs ..........................................................................510
Working with data logs ..........................................................................................................525
Limit to the size of data log files ............................................................................................526
Data log example program ...................................................................................................529
9.10
9.10.1
9.10.2
9.10.3
9.10.4
Data block control .................................................................................................................534
CREATE_DB (Create data block) .........................................................................................534
READ_DBL and WRIT_DBL (Read/write a data block in load memory) instructions ...........538
ATTR_DB (Read data block attribute) ..................................................................................541
DELETE_DB (Delete data block) ..........................................................................................542
9.11
9.11.1
Address handling ..................................................................................................................544
GEO2LOG (Determine the hardware identifier from the slot)...............................................544
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
13
Table of contents
10
9.11.2
9.11.3
9.11.4
9.11.5
LOG2GEO (Determine the slot from the hardware identifier) .............................................. 546
IO2MOD (Determine the hardware identifier from an I/O address) ..................................... 548
RD_ADDR (Determine the IO addresses from the hardware identifier) .............................. 550
GEOADDR system data type............................................................................................... 551
9.12
Common error codes for the Extended instructions ............................................................ 553
Technology instructions .......................................................................................................................555
10.1
10.1.1
10.1.1.1
10.1.1.2
10.1.1.3
10.1.2
10.1.2.1
10.1.2.2
10.1.2.3
10.1.2.4
10.1.2.5
10.1.3
10.1.3.1
10.1.3.2
10.1.3.3
10.1.3.4
10.1.3.5
10.1.3.6
10.1.3.7
10.1.3.8
10.1.3.9
10.1.3.10
10.1.4
10.1.4.1
10.1.4.2
10.1.4.3
Counting (High-speed counters) .......................................................................................... 555
CTRL_HSC_EXT (Control high-speed counter) instruction ................................................. 556
Instruction overview ............................................................................................................. 556
Example ............................................................................................................................... 557
CTRL_HSC_EXT Instruction System Data Types (SDT)..................................................... 561
Operating the high-speed counter ....................................................................................... 566
Synchronization function ...................................................................................................... 566
Gate function ........................................................................................................................ 567
Capture function ................................................................................................................... 569
Compare function ................................................................................................................. 570
Applications .......................................................................................................................... 571
Configuring a high-speed counter ........................................................................................ 572
Type of Counting .................................................................................................................. 573
Operating phase................................................................................................................... 574
Initial values ......................................................................................................................... 578
Input functions ...................................................................................................................... 578
Output function ..................................................................................................................... 579
Interrupt events .................................................................................................................... 580
Hardware input pin assignment ........................................................................................... 580
Hardware output pin assignment ......................................................................................... 582
HSC input memory addresses ............................................................................................. 583
Hardware identifier ............................................................................................................... 583
Legacy CTRL_HSC (Control high-speed counter) instruction ............................................. 584
Instruction overview ............................................................................................................. 584
Using CTRL_HSC ................................................................................................................ 586
HSC current count value ...................................................................................................... 587
10.2
10.2.1
10.2.2
10.2.2.1
10.2.2.2
10.2.2.3
10.2.2.4
10.2.3
10.2.3.1
10.2.3.2
10.2.3.3
10.2.4
10.2.4.1
10.2.4.2
10.2.4.3
10.2.5
10.2.6
10.2.7
PID control ........................................................................................................................... 588
Inserting the PID instruction and technology object............................................................. 590
PID_Compact ....................................................................................................................... 592
PID_Compact instruction ..................................................................................................... 592
PID_Compact instruction Process value limits .................................................................... 596
PID_Compact instruction ErrorBit parameters ..................................................................... 597
PID_Compact instruction Warning parameters .................................................................... 599
PID_3Step ............................................................................................................................ 600
PID_3Step instruction .......................................................................................................... 600
PID_3Step instruction ErrorBit parameters .......................................................................... 607
PID_3Step instruction Warning parameters ......................................................................... 609
PID_Temp ............................................................................................................................ 610
PID_Temp instruction ........................................................................................................... 610
PID_Temp ErrorBit parameters............................................................................................ 619
PID_Temp Warning parameters .......................................................................................... 621
Configuring the PID_Compact and PID_3Step controllers .................................................. 622
Configuring the PID_Temp controller ................................................................................... 625
Commissioning the PID_Compact and PID_3Step controllers ............................................ 640
S7-1200 Programmable controller
14
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
11
10.2.8
Commissioning the PID_Temp controller .............................................................................642
10.3
10.3.1
10.3.2
10.3.3
10.3.3.1
10.3.3.2
10.3.4
10.3.4.1
10.3.4.2
10.3.4.3
10.3.4.4
10.3.4.5
10.3.4.6
10.3.4.7
10.3.5
10.3.6
10.3.6.1
10.3.6.2
10.3.6.3
10.3.6.4
10.3.7
10.3.7.1
10.3.7.2
10.3.7.3
10.3.7.4
10.3.7.5
10.3.7.6
10.3.7.7
10.3.7.8
10.3.7.9
10.3.7.10
10.3.7.11
10.3.7.12
10.3.7.13
10.3.8
10.3.8.1
10.3.8.2
10.3.8.3
10.3.9
Motion control .......................................................................................................................653
Phasing .................................................................................................................................658
Configuring a pulse generator ..............................................................................................661
Open loop motion control ......................................................................................................662
Configuring the axis ..............................................................................................................662
Commissioning .....................................................................................................................666
Closed loop motion control ...................................................................................................672
Configuring the axis ..............................................................................................................672
ServoOBs ..............................................................................................................................679
Speed controlled operation ...................................................................................................681
Telegram 4 support ...............................................................................................................684
Simulation axis ......................................................................................................................689
Data adaptation .....................................................................................................................691
Axis control using the TM Pulse module...............................................................................702
Configuring the TO_CommandTable_PTO ...........................................................................708
Operation of motion control for S7-1200...............................................................................711
CPU outputs used for motion control ....................................................................................711
Hardware and software limit switches for motion control .....................................................713
Homing ..................................................................................................................................723
Jerk limit ................................................................................................................................730
Motion control instructions ....................................................................................................731
MC instruction overview ........................................................................................................731
MC_Power (Release/block axis) ...........................................................................................733
MC_Reset (Confirm error).....................................................................................................736
MC_Home (Home axis).........................................................................................................737
MC_Halt (Pause axis) ...........................................................................................................740
MC_MoveAbsolute (Position axis absolutely) .......................................................................742
MC_MoveRelative (Position axis relatively) ..........................................................................745
MC_MoveVelocity (Move axis at predefined velocity) ..........................................................747
MC_MoveJog (Move axis in jog mode) .................................................................................749
MC_CommandTable (Run axis commans as movement sequence) ...................................751
MC_ChangeDynamic (Change dynamc settings for the axis) ..............................................754
MC_WriteParam (write parameters of a technology object) .................................................756
MC_ReadParam instruction (read parameters of a technology object) ................................758
Monitoring active commands ................................................................................................760
Monitoring MC instructions with a "Done" output parameter ................................................760
Monitoring the MC_Velocity ..................................................................................................764
Monitoring the MC_MoveJog ................................................................................................768
ErrorIDs and ErrorInfos for motion control ............................................................................772
Communication ................................................................................................................................... 799
11.1
Asynchronous communication connections .........................................................................801
11.2
11.2.1
11.2.2
11.2.3
11.2.3.1
11.2.3.2
11.2.3.3
11.2.3.4
PROFINET ............................................................................................................................804
Creating a network connection .............................................................................................806
Configuring the Local/Partner connection path ....................................................................807
Assigning Internet Protocol (IP) addresses ..........................................................................810
Assigning IP addresses to programming and network devices ............................................810
Checking the IP address of your programming device .........................................................812
Assigning an IP address to a CPU online .............................................................................813
Configuring an IP address for a CPU in your project ............................................................814
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
15
Table of contents
11.2.4
11.2.5
11.2.6
11.2.7
11.2.8
11.2.8.1
11.2.8.2
11.2.8.3
11.2.8.4
11.2.8.5
11.2.8.6
11.2.8.7
11.2.8.8
11.2.8.9
11.2.8.10
11.2.8.11
11.2.8.12
11.2.8.13
11.2.8.14
11.2.8.15
11.2.8.16
11.2.8.17
11.2.9
11.2.9.1
11.2.9.2
11.2.9.3
11.2.9.4
11.2.10
11.2.10.1
11.2.11
11.2.11.1
11.2.11.2
11.2.11.3
11.2.12
11.2.12.1
11.2.12.2
11.2.12.3
11.2.12.4
11.2.13
11.2.13.1
11.2.13.2
11.2.13.3
11.2.13.4
11.2.13.5
11.2.14
11.2.14.1
11.2.14.2
11.2.14.3
11.2.15
11.2.15.1
11.2.15.2
11.2.15.3
Testing the PROFINET network .......................................................................................... 819
Locating the Ethernet (MAC) address on the CPU .............................................................. 820
Configuring Network Time Protocol (NTP) synchronization ................................................ 822
PROFINET device start-up time, naming, and address assignment ................................... 824
Open user communication ................................................................................................... 825
Protocols .............................................................................................................................. 825
TCP and ISO on TCP .......................................................................................................... 826
Communication services and used port numbers ................................................................ 827
Ad hoc mode ........................................................................................................................ 828
Connection IDs for the Open user communication instructions ........................................... 828
Parameters for the PROFINET connection ......................................................................... 832
TSEND_C and TRCV_C instructions ................................................................................... 836
Legacy TSEND_C and TRCV_C instructions ...................................................................... 848
TCON, TDISCON, TSEND, and TRCV instructions ............................................................ 856
Legacy TCON, TDISCON, TSEND, and TRCV instructions ............................................... 867
T_RESET (Terminate and re-establish an existing connection) instruction ........................ 878
T_DIAG (Checks the status of connection and reads information) instruction .................... 880
TMAIL_C (Send an email using the Ethernet interface of the CPU) instruction .................. 885
UDP ...................................................................................................................................... 894
TUSEND and TURCV .......................................................................................................... 895
T_CONFIG ........................................................................................................................... 901
Common parameters for instructions ................................................................................... 912
Communication with a programming device ........................................................................ 913
Establishing the hardware communications connection ...................................................... 914
Configuring the devices ....................................................................................................... 914
Assigning Internet Protocol (IP) addresses ......................................................................... 915
Testing your PROFINET network ........................................................................................ 915
HMI-to-PLC communication ................................................................................................. 916
Configuring logical network connections between two devices ........................................... 917
PLC-to-PLC communication ................................................................................................ 918
Configuring logical network connections between two devices ........................................... 919
Configuring the Local/Partner connection path between two devices ................................. 919
Configuring transmit (send) and receive parameters........................................................... 919
Configuring a CPU and PROFINET IO device .................................................................... 922
Adding a PROFINET IO device ........................................................................................... 922
Assigning CPUs and device names ..................................................................................... 923
Assigning Internet Protocol (IP) addresses ......................................................................... 924
Configuring the IO cycle time ............................................................................................... 924
Configuring a CPU and PROFINET I-device ....................................................................... 926
I-device functionality ............................................................................................................ 926
Properties and advantages of the I-device .......................................................................... 927
Characteristics of an I-device............................................................................................... 928
Data exchange between higher- and lower-level IO system ............................................... 931
Configuring the I-device ....................................................................................................... 933
Shared devices .................................................................................................................... 936
Shared device functionality .................................................................................................. 936
Example: Configuring a shared device (GSD configuration) ............................................... 939
Example: Configuring an I-device as a shared device ........................................................ 945
Media Redundancy Protocol (MRP) .................................................................................... 954
Media redundancy with ring topologies ............................................................................... 954
Using Media Redundancy Protocol (MRP) .......................................................................... 956
Configuring media redundancy ............................................................................................ 959
S7-1200 Programmable controller
16
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
12
11.2.16
11.2.16.1
11.2.16.2
11.2.17
11.2.17.1
11.2.18
11.2.19
11.2.20
11.2.21
S7 routing ..............................................................................................................................962
S7 routing between CPU and CP interfaces ........................................................................963
S7 routing between two CP interfaces..................................................................................963
Disabling SNMP ....................................................................................................................964
Disabling SNMP ....................................................................................................................965
Diagnostics ...........................................................................................................................967
Distributed I/O instructions ....................................................................................................967
Diagnostic instructions ..........................................................................................................967
Diagnostic events for distributed I/O .....................................................................................967
11.3
11.3.1
11.3.2
11.3.3
11.3.3.1
11.3.3.2
11.3.3.3
11.3.4
11.3.5
11.3.6
PROFIBUS ............................................................................................................................968
Communications services of the PROFIBUS CMs ...............................................................970
Reference to the PROFIBUS CM user manuals ..................................................................971
Configuring a DP master and slave device...........................................................................971
Adding the CM 1243-5 (DP master) module and a DP slave ...............................................971
Configuring logical network connections between two PROFIBUS devices ........................972
Assigning PROFIBUS addresses to the CM 1243-5 module and DP slave .........................972
Distributed I/O instructions ....................................................................................................974
Diagnostic instructions ..........................................................................................................974
Diagnostic events for distributed ...........................................................................................974
11.4
11.4.1
11.4.1.1
11.4.1.2
11.4.1.3
11.4.1.4
11.4.2
11.4.2.1
11.4.2.2
11.4.3
11.4.4
AS-i .......................................................................................................................................975
Configuring an AS-i master and slave device .......................................................................976
Adding the AS-i master CM 1243-2 and AS-i slave ..............................................................976
Configuring logical network connections between two AS-i devices ....................................977
Configuring the properties of the AS-i master CM1243-2.....................................................977
Assigning an AS-i address to an AS-i slave .........................................................................978
Exchanging data between the user program and AS-i slaves ..............................................981
STEP 7 basic configuration ..................................................................................................981
Configuring slaves with STEP 7 ...........................................................................................982
Distributed I/O instructions ....................................................................................................984
Working with AS-i online tools ..............................................................................................984
11.5
11.5.1
11.5.2
11.5.3
11.5.4
11.5.4.1
11.5.4.2
S7 communication ................................................................................................................986
GET and PUT (Read and write from a remote CPU) ...........................................................986
Creating an S7 connection ...................................................................................................991
Configuring the Local/Partner connection path between two devices ..................................992
GET/PUT connection parameter assignment .......................................................................992
Connection parameters.........................................................................................................993
Configuring a CPU-to-CPU S7 connection ...........................................................................995
Web server ........................................................................................................................................1001
12.1
Enabling the Web server ....................................................................................................1003
12.2
Configuring Web server users ............................................................................................1005
12.3
Accessing the Web pages from a PC .................................................................................1007
12.4
Accessing the Web pages from a mobile device ................................................................1009
12.5
Using a CP module to access Web pages .........................................................................1010
12.6
12.6.1
12.6.2
12.6.3
Standard Web pages ..........................................................................................................1011
Layout of the standard Web pages .....................................................................................1011
Basic pages ........................................................................................................................1012
Logging in and user privileges ............................................................................................1013
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
17
Table of contents
12.6.4
12.6.5
12.6.6
12.6.7
12.6.8
12.6.9
12.6.10
12.6.11
12.6.12
12.6.13
Introduction ........................................................................................................................ 1017
Start .................................................................................................................................... 1018
Diagnostics ......................................................................................................................... 1019
Diagnostic Buffer ................................................................................................................ 1022
Module Information ............................................................................................................ 1023
Communication .................................................................................................................. 1027
Tag status .......................................................................................................................... 1031
Watch tables ...................................................................................................................... 1033
Online backup .................................................................................................................... 1035
File Browser ....................................................................................................................... 1037
12.7
12.7.1
12.7.2
12.7.2.1
12.7.2.2
12.7.2.3
12.7.2.4
12.7.2.5
12.7.2.6
12.7.2.7
12.7.2.8
12.7.2.9
12.7.2.10
12.7.2.11
12.7.3
12.7.4
12.7.5
12.7.6
12.7.7
12.7.8
12.7.9
12.7.9.1
12.7.9.2
12.7.9.3
12.7.9.4
12.7.9.5
12.7.9.6
12.7.9.7
12.7.10
12.7.10.1
12.7.10.2
12.7.10.3
12.7.11
User-defined Web pages ................................................................................................... 1040
Creating HTML pages ........................................................................................................ 1041
AWP commands supported by the S7-1200 Web server .................................................. 1042
Reading variables .............................................................................................................. 1044
Writing variables................................................................................................................. 1045
Reading special variables .................................................................................................. 1047
Writing special variables .................................................................................................... 1048
Using an alias for a variable reference .............................................................................. 1049
Defining enum types .......................................................................................................... 1050
Referencing CPU variables with an enum type ................................................................. 1051
Creating fragments ............................................................................................................ 1052
Importing fragments ........................................................................................................... 1053
Combining definitions ......................................................................................................... 1054
Handling tag names that contain special characters ......................................................... 1055
Configuring use of user-defined Web pages ..................................................................... 1057
Configuring the entry page ................................................................................................. 1058
Programming the WWW instruction for user-defined web pages ...................................... 1059
Downloading the program blocks to the CPU .................................................................... 1060
Accessing the user-defined Web pages ............................................................................ 1061
Constraints specific to user-defined Web pages ............................................................... 1062
Example of a user-defined web page ................................................................................ 1063
Web page for monitoring and controlling a wind turbine.................................................... 1063
Reading and displaying controller data .............................................................................. 1065
Using an enum type ........................................................................................................... 1066
Writing user input to the controller ..................................................................................... 1067
Writing a special variable ................................................................................................... 1068
Reference: HTML listing of remote wind turbine monitor Web page ................................. 1068
Configuration in STEP 7 of the example Web page .......................................................... 1073
Setting up user-defined Web pages in multiple languages ............................................... 1074
Creating the folder structure .............................................................................................. 1074
Programming the language switch..................................................................................... 1075
Configuring STEP 7 to use a multi-language page structure ............................................ 1078
Advanced user-defined Web page control ......................................................................... 1078
12.8
12.8.1
12.8.2
12.8.3
12.8.4
12.8.5
Constraints ......................................................................................................................... 1082
Use of JavaScript ............................................................................................................... 1083
Feature restrictions when the Internet options do not allow cookies ................................. 1083
Rules for entering tag names and values .......................................................................... 1084
Importing the Siemens security certificate ......................................................................... 1085
Importing CSV format data logs to non-USA/UK versions of Microsoft Excel ................... 1086
S7-1200 Programmable controller
18
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
13
Communication processor and Modbus TCP ......................................................................................1087
13.1
Using the serial communication interfaces .........................................................................1087
13.2
Biasing and terminating an RS485 network connector .......................................................1088
13.3
13.3.1
13.3.2
13.3.3
13.3.3.1
13.3.3.2
13.3.3.3
13.3.4
13.3.4.1
13.3.4.2
13.3.5
13.3.5.1
13.3.5.2
13.3.5.3
13.3.5.4
13.3.5.5
13.3.5.6
13.3.5.7
13.3.5.8
13.3.5.9
13.3.5.10
13.3.5.11
13.3.5.12
13.3.6
13.3.6.1
13.3.7
13.3.7.1
13.3.7.2
13.3.7.3
13.3.7.4
13.3.7.5
Point-to-point (PtP) communication ....................................................................................1090
PtP, Freeport communication .............................................................................................1090
3964(R) communication ......................................................................................................1092
Configuring the PtP Freeport communication .....................................................................1093
Managing flow control .........................................................................................................1095
Configuring transmit (send) parameters .............................................................................1096
Configuring receive parameters ..........................................................................................1097
Configuring 3964(R) communication ..................................................................................1105
Configuring the 3964(R) communication ports ...................................................................1105
Configuring the 3964(R) priority and protocol parameters .................................................1106
Point-to-point instructions ...................................................................................................1108
Common parameters for Point-to-Point instructions ...........................................................1108
Port_Config (Configure communication parameters dynamically) .....................................1110
Send_Config (Configure serial transmission parameters dynamically) ..............................1112
Receive_Config (Configure serial receive parameters dynamically) ..................................1115
P3964_Config (Configuring the 3964(R) protocol) .............................................................1120
Send_P2P (Transmit send buffer data) ..............................................................................1122
Receive_P2P (Enable receive messages)..........................................................................1126
Receive_Reset (Delete receive buffer) ...............................................................................1128
Signal_Get (Query RS-232 signals)....................................................................................1129
Signal_Set (Set RS-232 signals) ........................................................................................1130
Get_Features ......................................................................................................................1131
Set_Features .......................................................................................................................1132
Programming the PtP communications ..............................................................................1134
Polling architecture .............................................................................................................1135
Example: Point-to-Point communication .............................................................................1136
Configuring the communication module .............................................................................1137
RS422 and RS485 operating modes ..................................................................................1140
Programming the STEP 7 program ....................................................................................1143
Configuring the terminal emulator .......................................................................................1145
Running the example program ...........................................................................................1145
13.4
13.4.1
13.4.2
13.4.3
13.4.3.1
13.4.3.2
13.4.3.3
13.4.3.4
13.4.4
13.4.5
13.4.6
Universal serial interface (USS) communication ................................................................1146
Selecting the version of the USS instructions .....................................................................1149
Requirements for using the USS protocol ..........................................................................1150
USS instructions .................................................................................................................1153
USS_Port_Scan (Edit communication using USS network) ...............................................1153
USS_Drive_Control (Swap data with drive) ........................................................................1154
USS_Read_Param (Readout parameters from the drive) ..................................................1157
USS_Write_Param (Change parameters in the drive) ........................................................1158
USS status codes ...............................................................................................................1160
USS general drive setup requirements ...............................................................................1162
Example: USS general drive connection and setup ...........................................................1162
13.5
13.5.1
13.5.2
13.5.2.1
13.5.2.2
Modbus communication ......................................................................................................1166
Overview of Modbus RTU and Modbus TCP communication ............................................1166
Modbus TCP .......................................................................................................................1169
Overview .............................................................................................................................1169
Selecting the version of the Modbus TCP instructions .......................................................1170
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
19
Table of contents
13.5.2.3
13.5.2.4
13.5.3
13.5.3.1
13.5.3.2
13.5.3.3
13.5.3.4
13.5.3.5
Modbus TCP instructions ................................................................................................... 1171
Modbus TCP examples ...................................................................................................... 1185
Modbus RTU ...................................................................................................................... 1191
Overview ............................................................................................................................ 1191
Selecting the version of the Modbus RTU instructions ...................................................... 1193
Maximum number of supported Modbus slaves ................................................................ 1193
Modbus RTU instructions ................................................................................................... 1194
Modbus RTU examples ..................................................................................................... 1213
13.6
13.6.1
13.6.1.1
13.6.1.2
13.6.1.3
13.6.1.4
13.6.1.5
13.6.1.6
13.6.1.7
13.6.1.8
Legacy PtP communication (CM/CB 1241 only) ................................................................ 1217
Legacy point-to-point instructions ...................................................................................... 1218
PORT_CFG (Configure communication parameters dynamically) .................................... 1218
SEND_CFG (Configure serial transmission parameters dynamically) .............................. 1220
RCV_CFG (Configure serial receive parameters dynamically) ......................................... 1221
SEND_PTP (Transmit send buffer data) ............................................................................ 1226
RCV_PTP (Enable receive messages) .............................................................................. 1229
RCV_RST (Delete receive buffer) ...................................................................................... 1231
SGN_GET (Query RS-232 signals) ................................................................................... 1232
SGN_SET (Set RS-232 signals) ........................................................................................ 1233
13.7
13.7.1
13.7.2
13.7.3
13.7.3.1
13.7.3.2
13.7.3.3
13.7.3.4
13.7.4
13.7.5
Legacy USS communication (CM/CB 1241 only) .............................................................. 1234
Selecting the version of the USS instructions .................................................................... 1235
Requirements for using the USS protocol ......................................................................... 1236
Legacy USS instructions .................................................................................................... 1239
USS_PORT (Edit communication using USS network) instruction .................................... 1239
USS_DRV (Swap data with drive) instruction .................................................................... 1240
USS_RPM (Readout parameters from the drive) instruction ............................................. 1243
USS_WPM (Change parameters in the drive) instruction.................................................. 1244
Legacy USS status codes .................................................................................................. 1246
Legacy USS general drive setup requirements ................................................................. 1248
13.8
13.8.1
13.8.2
13.8.3
13.8.3.1
13.8.3.2
13.8.4
13.8.4.1
13.8.4.2
13.8.4.3
13.8.4.4
13.8.4.5
Legacy Modbus TCP communication ................................................................................ 1249
Overview ............................................................................................................................ 1249
Selecting the version of the Modbus TCP instructions ...................................................... 1249
Legacy Modbus TCP instructions ...................................................................................... 1250
MB_CLIENT (Communicate using PROFINET as Modbus TCP client) ............................ 1250
MB_SERVER (Communicate using PROFINET as Modbus TCP server) ........................ 1257
Legacy Modbus TCP examples ......................................................................................... 1264
Example: Legacy MB_SERVER Multiple TCP connections .............................................. 1264
Example: Legacy MB_CLIENT 1: Multiple requests with common TCP connection ......... 1265
Example: Legacy MB_CLIENT 2: Multiple requests with different TCP connections ........ 1266
Example: Legacy MB_CLIENT 3: Output image write request .......................................... 1267
Example: Legacy MB_CLIENT 4: Coordinating multiple requests .................................... 1268
13.9
13.9.1
13.9.2
13.9.3
13.9.3.1
13.9.3.2
13.9.3.3
13.9.4
13.9.4.1
13.9.4.2
Legacy Modbus RTU communication (CM/CB 1241 only) ................................................ 1269
Overview ............................................................................................................................ 1269
Selecting the version of the Modbus RTU instructions ...................................................... 1269
Legacy Modbus RTU instructions ...................................................................................... 1270
MB_COMM_LOAD (Configure port on the PtP module for Modbus RTU) ........................ 1270
MB_MASTER (Communicate using the PtP port as Modbus RTU master) ...................... 1272
MB_SLAVE (Communicate using the PtP port as Modbus RTU slave) ............................ 1278
Legacy Modbus RTU examples ......................................................................................... 1285
Example: Legacy Modbus RTU master program............................................................... 1285
Example: Legacy Modbus RTU slave program ................................................................. 1287
S7-1200 Programmable controller
20
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
13.10
13.10.1
13.10.2
13.10.3
13.10.4
13.10.5
13.10.6
13.10.7
14
TeleService communication (SMTP email) .........................................................................................1301
14.1
15
Industrial Remote Communication (IRC) ............................................................................1288
Telecontrol CPs overview ...................................................................................................1288
Connection to a GSM network ............................................................................................1291
Applications of the CP 1242-7 ............................................................................................1293
Other properties of the CP 1242-7......................................................................................1294
Further information..............................................................................................................1294
Accessories .........................................................................................................................1295
Configuration examples for telecontrol ...............................................................................1296
TM_Mail (Send email) instruction .......................................................................................1301
Online and diagnostic tools ................................................................................................................1309
15.1
Status LEDs ........................................................................................................................1309
15.2
Going online and connecting to a CPU...............................................................................1313
15.3
Assigning a name to a PROFINET IO device online ..........................................................1314
15.4
Setting the IP address and time of day ...............................................................................1316
15.5
Resetting to factory settings ...............................................................................................1317
15.6
Updating firmware ...............................................................................................................1318
15.7
Formatting a SIMATIC memory card from STEP 7 ............................................................1320
15.8
CPU operator panel for the online CPU..............................................................................1321
15.9
Monitoring the cycle time and memory usage ....................................................................1321
15.10
Displaying diagnostic events in the CPU ............................................................................1322
15.11
Comparing offline and online CPUs ....................................................................................1323
15.12
Performing an online/offline topology comparison ..............................................................1324
15.13
15.13.1
15.13.2
15.13.3
15.13.4
15.13.4.1
15.13.4.2
15.13.5
15.13.5.1
15.13.5.2
Monitoring and modifying values in the CPU ......................................................................1325
Going online to monitor the values in the CPU ...................................................................1326
Displaying status in the program editor ..............................................................................1327
Capturing a snapshot of the online values of a DB for restoring values.............................1327
Using a watch table to monitor and modify values in the CPU ...........................................1329
Using a trigger when monitoring or modifying PLC tags ....................................................1330
Enabling outputs in STOP mode ........................................................................................1331
Forcing values in the CPU ..................................................................................................1332
Using the force table ...........................................................................................................1332
Operation of the Force function ..........................................................................................1333
15.14
15.14.1
15.14.2
15.14.3
15.14.4
15.14.5
15.14.6
15.14.7
Downloading in RUN mode ................................................................................................1335
Prerequisites for "Download in RUN mode" .......................................................................1336
Changing your program in RUN mode ...............................................................................1337
Downloading selected blocks .............................................................................................1338
Downloading a single selected block with a compile error in another block.......................1340
Modifying and downloading existing blocks in RUN mode .................................................1341
System reaction if the download process fails ....................................................................1344
Considerations when downloading in RUN mode ..............................................................1345
15.15
Tracing and recording CPU data on trigger conditions .......................................................1347
15.16
Determining the type of wire break condition from an SM 1231 module ............................1349
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
21
Table of contents
15.17
15.17.1
15.17.2
15.17.3
A
Backing up and restoring a CPU........................................................................................ 1352
Backup and restore options ............................................................................................... 1352
Backing up an online CPU ................................................................................................. 1354
Restoring a CPU ................................................................................................................ 1356
Technical specifications ..................................................................................................................... 1359
A.1
Siemens Online Support website ....................................................................................... 1359
A.2
General technical specifications ........................................................................................ 1359
A.3
PROFINET interface X1 port pinouts ................................................................................. 1369
A.4
A.4.1
A.4.2
A.4.3
A.4.4
A.4.4.1
A.4.4.2
A.4.4.3
A.4.5
CPU 1211C ........................................................................................................................ 1370
General specifications and features................................................................................... 1370
Timers, counters, and code blocks supported by CPU 1211C .......................................... 1372
Digital inputs and outputs ................................................................................................... 1376
Analog inputs ..................................................................................................................... 1377
Step response of the built-in analog inputs of the CPU ..................................................... 1378
Sample time for the built-in analog ports of the CPU......................................................... 1378
Measurement ranges of the analog inputs for voltage (CPUs) .......................................... 1378
CPU 1211C wiring diagrams.............................................................................................. 1379
A.5
A.5.1
A.5.2
A.5.3
A.5.4
A.5.4.1
A.5.4.2
A.5.4.3
A.5.5
CPU 1212C ........................................................................................................................ 1382
General specifications and features................................................................................... 1382
Timers, counters, and code blocks supported by CPU 1212C .......................................... 1384
Digital inputs and outputs ................................................................................................... 1388
Analog inputs ..................................................................................................................... 1390
Step response of the built-in analog inputs of the CPU ..................................................... 1390
Sample time for the built-in analog ports of the CPU......................................................... 1391
Measurement ranges of the analog inputs for voltage (CPUs) .......................................... 1391
CPU 1212C wiring diagrams.............................................................................................. 1392
A.6
A.6.1
A.6.2
A.6.3
A.6.4
A.6.4.1
A.6.4.2
A.6.4.3
A.6.5
CPU 1214C ........................................................................................................................ 1395
General specifications and features................................................................................... 1395
Timers, counters and code blocks supported by CPU 1214C ........................................... 1397
Digital inputs and outputs ................................................................................................... 1401
Analog inputs ..................................................................................................................... 1403
Step response of the built-in analog inputs of the CPU ..................................................... 1403
Sample time for the built-in analog ports of the CPU......................................................... 1404
Measurement ranges of the analog inputs for voltage (CPUs) .......................................... 1404
CPU 1214C wiring diagrams.............................................................................................. 1405
A.7
A.7.1
A.7.2
A.7.3
A.7.4
A.7.4.1
A.7.4.2
A.7.4.3
A.7.4.4
A.7.5
CPU 1215C ........................................................................................................................ 1409
General specifications and features................................................................................... 1409
Timers, counters and code blocks supported by CPU 1215C ........................................... 1411
Digital inputs and outputs ................................................................................................... 1415
Analog inputs and outputs ................................................................................................. 1417
Step response of built-in analog inputs of the CPU ........................................................... 1417
Sample time for the built-in analog ports of the CPU......................................................... 1418
Measurement ranges of the analog inputs for voltage (CPUs) .......................................... 1418
Analog output specifications .............................................................................................. 1419
CPU 1215C wiring diagrams.............................................................................................. 1420
A.8
A.8.1
A.8.2
CPU 1217C ........................................................................................................................ 1425
General specifications and features................................................................................... 1425
Timers, counters and code blocks supported by CPU 1217C ........................................... 1427
S7-1200 Programmable controller
22
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
A.8.3
A.8.4
A.8.4.1
A.8.4.2
A.8.4.3
A.8.4.4
A.8.4.5
A.8.5
A.8.6
A.8.7
Digital inputs and outputs ...................................................................................................1430
Analog inputs and outputs ..................................................................................................1435
Analog input specifications .................................................................................................1435
Step response of built-in analog inputs of the CPU ............................................................1435
Sample time for the built-in analog ports of the CPU .........................................................1436
Measurement ranges of the analog inputs for voltage (CPUs)...........................................1436
Analog output specifications ...............................................................................................1436
CPU 1217C wiring diagrams ..............................................................................................1438
CPU 1217C Differential Input (DI) detail and application example .....................................1440
CPU 1217C Differential Output (DQ) detail and application example ................................1441
A.9
A.9.1
A.9.2
A.9.3
A.9.4
A.9.5
Digital signal modules (SMs) ..............................................................................................1442
SM 1221 digital input specifications ....................................................................................1442
SM 1222 8-point digital output specifications .....................................................................1444
SM 1222 16-point digital output specifications ...................................................................1446
SM 1223 digital input/output V DC specifications ...............................................................1451
SM 1223 digital input/output V AC specifications ...............................................................1456
A.10
A.10.1
A.10.2
A.10.3
A.10.4
A.10.5
A.10.6
A.10.7
Analog signal modules (SMs) .............................................................................................1459
SM 1231 analog input module specifications .....................................................................1459
SM 1232 analog output module specifications ...................................................................1464
SM 1234 analog input/output module specifications ..........................................................1466
Step response of the analog inputs ....................................................................................1470
Sample time and update times for the analog inputs .........................................................1470
Measurement ranges of the analog inputs for voltage and current (SB and SM) ..............1471
Measurement ranges of the analog outputs for voltage and current (SB and SM) ............1472
A.11
A.11.1
A.11.1.1
A.11.1.2
A.11.2
A.11.2.1
Thermocouple and RTD signal modules (SMs) ..................................................................1473
SM 1231 Thermocouple......................................................................................................1473
Basic operation for a thermocouple ....................................................................................1476
Selection tables for the SM 1231 thermocouple .................................................................1477
SM 1231 RTD .....................................................................................................................1479
Selection tables for the SM 1231 RTD ...............................................................................1482
A.12
A.12.1
A.12.1.1
A.12.1.2
A.12.1.3
A.12.1.4
Technology modules ...........................................................................................................1485
SM 1278 4xIO-Link Master SM ...........................................................................................1485
SM 1278 4xIO-Link Master overview ..................................................................................1488
Connecting ..........................................................................................................................1491
Parameters/address space .................................................................................................1493
Interrupt, error, and system alarms .....................................................................................1496
A.13
A.13.1
A.13.2
A.13.3
A.13.4
Digital signal boards (SBs) .................................................................................................1500
SB 1221 200 kHz digital input specifications ......................................................................1500
SB 1222 200 kHz digital output specifications ....................................................................1502
SB 1223 200 kHz digital input / output specifications .........................................................1505
SB 1223 2 X 24 V DC input / 2 X 24 V DC output specifications .......................................1508
A.14
A.14.1
A.14.2
A.14.3
A.14.3.1
A.14.3.2
A.14.3.3
A.14.3.4
Analog signal boards (SBs) ................................................................................................1511
SB 1231 1 analog input specifications ................................................................................1511
SB 1232 1 analog output specifications..............................................................................1514
Measurement ranges for analog inputs and outputs ..........................................................1516
Step response of the analog inputs ....................................................................................1516
Sample time and update times for the analog inputs .........................................................1516
Measurement ranges of the analog inputs for voltage and current (SB and SM) ..............1516
Measurement ranges of the analog outputs for voltage and current (SB and SM) ............1517
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
23
Table of contents
A.14.4
A.14.4.1
A.14.4.2
A.14.5
A.14.5.1
A.14.5.2
Thermocouple signal boards (SBs).................................................................................... 1519
SB 1231 1 analog thermocouple input specifications ........................................................ 1519
Basic operation for a thermocouple ................................................................................... 1520
RTD signal boards (SBs) ................................................................................................... 1523
SB 1231 1 analog RTD input specifications ...................................................................... 1523
Selection tables for the SB 1231 RTD ............................................................................... 1526
A.15
BB 1297 Battery board ....................................................................................................... 1528
A.16
A.16.1
A.16.1.1
A.16.1.2
A.16.1.3
A.16.1.4
A.16.2
A.16.2.1
A.16.2.2
A.16.2.3
A.16.3
A.16.3.1
A.16.3.2
A.16.4
A.16.4.1
A.16.4.2
A.16.4.3
Communication interfaces ................................................................................................. 1530
PROFIBUS ......................................................................................................................... 1530
CM 1242-5 PROFIBUS DP SLAVE ................................................................................... 1530
Pinout of the D-sub socket of the CM 1242-5 .................................................................... 1531
CM 1243-5 PROFIBUS DP Master .................................................................................... 1532
Pinout of the D-sub socket of the CM 1243-5 .................................................................... 1533
CP 1242-7 .......................................................................................................................... 1534
CP 1242-7 GPRS ............................................................................................................... 1534
GSM/GPRS antenna ANT794-4MR................................................................................... 1536
Flat antenna ANT794-3M ................................................................................................... 1537
CM 1243-2 AS-i master ..................................................................................................... 1538
Technical data for the AS-i master CM 1243-2 .................................................................. 1538
Electrical connections of the AS-i master .......................................................................... 1539
RS232, RS422, and RS485 ............................................................................................... 1541
CB 1241 RS485 specifications .......................................................................................... 1541
CM 1241 RS232 specifications .......................................................................................... 1543
CM 1241 RS422/485 specifications ................................................................................... 1544
A.17
TeleService (TS Adapter and TS Adapter modular) .......................................................... 1546
A.18
SIMATIC memory cards ..................................................................................................... 1546
A.19
Input simulators .................................................................................................................. 1547
A.20
S7-1200 Potentiometer module ......................................................................................... 1549
A.21
I/O expansion cable ........................................................................................................... 1550
A.22
A.22.1
A.22.2
A.22.3
A.22.4
A.22.5
A.22.6
Companion products .......................................................................................................... 1551
PM 1207 power module ..................................................................................................... 1551
CSM 1277 compact switch module.................................................................................... 1551
CM CANopen module ........................................................................................................ 1552
RF120C communications module ...................................................................................... 1552
SM 1238 Energy meter module ......................................................................................... 1553
SIWAREX electronic weighing systems ............................................................................ 1553
B
Calculating a power budget ................................................................................................................ 1555
C
Ordering Information .......................................................................................................................... 1559
C.1
CPU modules ..................................................................................................................... 1559
C.2
Signal modules (SMs), signal boards (SBs), and battery boards (BBs) ............................ 1560
C.3
Communication .................................................................................................................. 1561
C.4
Fail-Safe CPUs and signal modules .................................................................................. 1563
C.5
Other modules.................................................................................................................... 1563
C.6
Memory cards .................................................................................................................... 1563
S7-1200 Programmable controller
24
System Manual, V4.2, 09/2016, A5E02486680-AK
Table of contents
D
C.7
Basic HMI devices ..............................................................................................................1564
C.8
Spare parts and other hardware .........................................................................................1564
C.9
Programming software ........................................................................................................1569
Device exchange and spare parts compatibility ..................................................................................1571
D.1
Exchanging a V3.0 CPU for a V4.2 CPU ............................................................................1571
D.2
S7-1200 V3.0 and earlier terminal block spare kits ............................................................1578
Index..................................................................................................................................................1581
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
25
Table of contents
S7-1200 Programmable controller
26
System Manual, V4.2, 09/2016, A5E02486680-AK
1
Product overview
1.1
Introducing the S7-1200 PLC
The S7-1200 controller provides the flexibility and power to control a wide variety of devices
in support of your automation needs. The compact design, flexible configuration, and
powerful instruction set combine to make the S7-1200 a perfect solution for controlling a
wide variety of applications.
The CPU combines a microprocessor, an integrated power supply, input and output circuits,
built-in PROFINET, high-speed motion control I/O, and on-board analog inputs in a compact
housing to create a powerful controller. After you download your program, the CPU contains
the logic required to monitor and control the devices in your application. The CPU monitors
the inputs and changes the outputs according to the logic of your user program, which can
include Boolean logic, counting, timing, complex math operations, motion control, and
communications with other intelligent devices.
The CPU provides a PROFINET port for communication over a PROFINET network.
Additional modules are available for communicating over PROFIBUS, GPRS, RS485,
RS232, RS422, IEC, DNP3, and WDC (Wideband Data Communication) networks.
① Power connector
② Memory card slot under top
door
③ Removable user wiring connectors (behind the doors)
④ Status LEDs for the onboard I/O
⑤ PROFINET connector (on
the bottom of the CPU)
Several security features help protect access to both the CPU and the control program:
● Every CPU provides password protection (Page 210) that allows you to configure access
to the CPU functions.
● You can use "know-how protection" (Page 213) to hide the code within a specific block.
● You can use copy protection (Page 214) to bind your program to a specific memory card
or CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
27
Product overview
1.1 Introducing the S7-1200 PLC
Table 1- 1
Comparing the CPU models
Feature
CPU 1211C
Physical size (mm)
User memory
Local on-board I/O
CPU 1212C
CPU 1214C
90 x 100 x 75
CPU 1215C
CPU 1217C
110 x 100 x 75
130 x 100 x 75
150 x 100 x 75
Work
50 Kbytes
75 Kbytes
100 Kbytes
125 Kbytes
150 Kbytes
Load
1 Mbyte
2 Mbytes
4 Mbytes
Retentive
10 Kbytes
Digital
6 inputs/
4 outputs
8 inputs/
6 outputs
14 inputs/
10 output
Analog
2 inputs
Process image size Inputs (I)
2 inputs/2 output
1024 bytes
Outputs (Q) 1024 bytes
Bit memory (M)
4096 bytes
8192 bytes
Signal module (SM) expansion
None
Signal board (SB), Battery board
(BB), or communication board
(CB)
1
Communication module (CM)
(left-side expansion)
3
High-speed counters
Total
Up to 6 configured to use any built-in or SB inputs
1 MHz
-
100/180
kHz
Ia.0 to Ia.5
30/120 kHz
--
2
8
Ib.2 to Ib.5
Ia.6 to Ia.7
Ia.6 to Ib.5
Ia.6 to Ib.1
200 kHz3
Pulse outputs2
Total
Up to 4 configured to use any built-in or SB outputs
1 MHz
--
Qa.0 to Qa.3
100 kHz
Qa.0 to Qa.3
Qa.4 to Qb.1
20 kHz
--
Memory card
Data logs
Qa.4 to Qa.5
Qa.4 to Qb.1
--
SIMATIC memory card (optional)
Number
Maximum 8 open at one time
Size
500 MB per data log or as limited by maximum available load memory
Real time clock retention time
20 days, typ./12 day min. at 40 degrees C (maintenance-free Super Capacitor)
PROFINET
Ethernet communication port
1
Real math execution speed
2.3 μs/instruction
Boolean execution speed
0.08 μs/instruction
2
1
The slower speed is applicable when the HSC is configured for quadrature mode of operation.
2
For CPU models with relay outputs, you must install a digital signal (SB) to use the pulse outputs.
3
Up to 200 kHz are available with the SB 1221 DI x 24 V DC 200 kHz and SB 1221 DI 4 x 5 V DC 200 kHz.
The different CPU models provide a diversity of features and capabilities that help you create
effective solutions for your varied applications. For detailed information about a specific
CPU, see the technical specifications (Page 1359).
S7-1200 Programmable controller
28
System Manual, V4.2, 09/2016, A5E02486680-AK
Product overview
1.1 Introducing the S7-1200 PLC
Table 1- 2
Blocks, timers, and counters supported by S7-1200
Element
Blocks
Description
Type
Size
OB, FB, FC, DB
CPU Model
CPU 1211C CPU 1212C CPU 1214C CPU 1215C CPU 1217C
Code blocks
50KB
64KB
64KB
64KB
64KB
Linked1 data blocks
50KB
75KB
100KB
125KB
150KB
Unlinked2 data blocks
256KB
256KB
256KB
256KB
256KB
Quantity
Up to 1024 blocks total (OBs + FBs + FCs + DBs)
Nesting depth
16 from the program cycle or startup OB;
6 from any interrupt event OB
OBs
Timers
Counters
Monitoring
Status of 2 code blocks can be monitored simultaneously
Program cycle
Multiple
Startup
Multiple
Time-delay interrupts
4 (1 per event)
Cyclic interrupts
4 (1 per event)
Hardware interrupts
50 (1 per event)
Time error interrupts
1
Diagnostic error interrupts
1
Pull or plug of modules
1
Rack or station failure
1
Time of day
Multiple
Status
1
Update
1
Profile
1
Type
IEC
Quantity
Limited only by memory size
Storage
Structure in DB, 16 bytes per timer
Type
IEC
Quantity
Limited only by memory size
Storage
Structure in DB, size dependent upon count type
1
Stored in work memory and load memory
2
Stored only in load memory
•
SInt, USInt: 3 bytes
•
Int, UInt: 6 bytes
•
DInt, UDInt: 12 bytes
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
29
Product overview
1.2 Expansion capability of the CPU
1.2
Expansion capability of the CPU
The S7-1200 family provides a variety of modules and plug-in boards for expanding the
capabilities of the CPU with additional I/O or other communication protocols. For detailed
information about a specific module, see the technical specifications (Page 1359).
①
②
③
④
Communication module (CM) or communication processor (CP) (Page 1530)
CPU (CPU 1211C (Page 1370), CPU 1212C (Page 1382), CPU 1214C (Page 1395),
CPU 1215C (Page 1409), CPU 1217C (Page 1425))
Signal board (SB) (digital SB (Page 1500), analog SB (Page 1511)), communication board
(CB) (Page 1541), or Battery Board (BB) CPU (CPU 1211C, CPU 1212C, CPU 1214C, CPU
1215C, CPU 1217C) (Page 1528)
Signal module (SM) (digital SM (Page 1442), analog SM (Page 1459), thermocouple SM
(Page 1473), RTD SM (Page 1479), technology SM) (Page 1485)
S7-1200 Programmable controller
30
System Manual, V4.2, 09/2016, A5E02486680-AK
Product overview
1.2 Expansion capability of the CPU
Table 1- 3
S7-1200 expansion modules
Type of module
Description
The CPU supports one plug-in expansion
board:
•
A signal board (SB) provides additional
I/O for your CPU. The SB connects on
the front of the CPU.
•
A communication board (CB) allows
you to add another communication port
to your CPU.
•
A battery board (BB) allows you to
provide long term backup of the
realtime clock.
① Status LEDs on the SB
② Removable user wiring connector
Signal modules (SMs) add additional functionality to the CPU. SMs connect to the
right side of the CPU.
•
Digital I/O
•
Analog I/O
•
RTD and thermocouple
•
SM 1278 IO-Link Master
•
SM 1238 Energy Meter
(https://support.industry.siemens.com/
cs/ww/en/view/109483435)
① Status LEDs
② Bus connector slide tab
③ Removable user wiring connector
Communication modules (CMs) and
communications processors (CPs) add
communication options to the CPU, such
as for PROFIBUS or RS232/RS485 connectivity (for PtP, Modbus or USS), or the
AS-i master.
A CP provides capabilities for other types
of communication, such as connecting to
the CPU over a GPRS, LTE, IEC, DNP3,
or WDC network.
•
The CPU supports up to three CMs or
CPs
•
Each CM or CP connects to the left
side of the CPU (or to the left side of
another CM or CP)
① Status LEDs
② Communication connector
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
31
Product overview
1.3 Basic HMI panels
1.3
Basic HMI panels
The SIMATIC HMI Basic Panels provide touch-screen devices for basic operator control and
monitoring tasks. All panels have a protection rating for IP65 and have CE, UL, cULus, and
NEMA 4x certification.
The available Basic HMI panels (Page 1564)are described below:
● KTP400 Basic: 4" Touch screen with 4 configurable keys, a resolution of 480 x 272 and
800 tags
● KTP700 Basic: 7" Touch screen with 8 configurable keys, a resolution of 800 x 480 and
800 tags
● KTP700 Basic DP: 7" Touch screen with 8 configurable keys, a resolution of 800 x 480
and 800 tags
● KTP900 Basic: 9" Touch screen with 8 configurable keys, a resolution of 800 x 480 and
800 tags
● KTP1200 Basic: 12" Touch screen with 10 configurable keys, a resolution of 800 x 480
and 800 tags
● KTP 1200 Basic DP: 12" Touch screen with 10 configurable keys, a resolution of 800 x
400 and 800 tags
S7-1200 Programmable controller
32
System Manual, V4.2, 09/2016, A5E02486680-AK
2
New features
The following features are new in the V4.2 release:
● Enhancements to the Web server (Page 1001):
– More shared functionality with the S7-1500 Web server
– Ability to define user-defined Web page as start page
– New or improved standard Web pages:
Watch tables (Page 1033)
Online backup (Page 1035)
Communication (Page 1027): inclusion of communication statistics
● New programming instructions:
– Basic instructions:
LOWER_BOUND: (Read out ARRAY low limit) (Page 277)
UPPER_BOUND: (Read out ARRAY high limit) (Page 279)
– Extended instructions
GetSymbolName (Read out a tag on the input parameter) (Page 370)
GetSymbolPath (Query composite global name of the input parameter assignment)
(Page 373)
GetInstanceName (Read out name of the block instance) (Page 376)
GetInstancePath (Query composite global name of the block instance) (Page 379)
GetBlockName (Read out name of the block) (Page 381)
GETIO (Read process image) (Page 388)
SETIO (Transfer process image) (Page 389)
GETIO_PART (Read process image area) (Page 390)
SETIO_PART (Transfer process image area) (Page 392)
D_ACT_DP (Enable/disable PROFINET IO devices) (Page 398)
RCVREC (I-device/I-slave receive data record) (Page 411)
PRVREC (I-device/I-slave make data record available) (Page 413)
PROFIenergy (Page 419) instructions for energy management
Gen_UsrMsg (Generate user diagnostic alarms) (Page 436)
RD_SINFO (Read current OB start information) (Page 440)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
33
New features
Get_Name (Read the name of a PROFINET IO device) (Page 453)
GetStationInfo (Read the IP or MAC address of a PROFINET IO device) (Page 460)
CTRL_PTO (Pulse train output) (Page 488)
DataLogClear (Empty data log) (Page 518)
DataLogDelete (Delete data log) (Page 520)
CREATE_DB (Create data block) (Page 534)
ATTR_DB (Read data block attribute) (Page 541)
DELETE_DB (Delete data block) (Page 542)
● New communication capabilities:
– Time synchronization (Page 181)
– Media Redundancy Protocol (MRP) (Page 954) (client-only)
– S7-routing (Page 962)
– Autonegotiation (Page 814)
– PROFINET interface X1 port pinouts (Page 1369)
● New High-Speed Counter (HSC) capabilities:
– Added support to the CTRL_HSC_EXT (Control high-speed counter) instruction for
Count and Frequency mode (Page 556)
– Enable and disable the HSC with the Gate input (Page 567)
– Capture the HSC’s count value with Capture input (Page 569)
– Generate an output pulse on HSC events with the Compare output (Page 570)
– Ability to change HSC counting limits and an additional reference value (Page 578)
– Improved accuracy of frequency measurement (Page 573)
● New motion control capabilities:
– Speed controlled operation (Page 681)
– Telegram 4 support (Page 684)
– Simulation axis (Page 689)
– Data adaptation (Page 691)
– Axis control using the TM Pulse module (Page 702)
– Homing reference point switch level (Page 726)
– Hardware limit switch edge detection configuration on address change (Page 716)
● Backup and restore of an online S7-1200 CPU from STEP 7 (Page 1352)
● Enhancements to capturing and loading an online DB snapshot (Page 1327)
● Opportunity to synchronize the online CPU with the offline project (Page 219) under
certain conditions
● Reduction of repeated security event entries in the Diagnostics Buffer (Page 114)
● Ability to format a SIMATIC memory card from STEP 7 (Page 1320)
S7-1200 Programmable controller
34
System Manual, V4.2, 09/2016, A5E02486680-AK
New features
● Ability to prevent copies from internal load memory to external load memory (SIMATIC
memory card) (Page 212)
● Support for the 3964R protocol (Page 1092) in point-to-point communications
● Ability to declare a tag in I or Q memory using a PLC data type (Page 133) (user-defined
data type or UDT)
● Ability to save trace job measurements (Page 1347) to external load memory
● Maximum size of 256KB for unlinked (load memory) data blocks, regardless of CPU
model (Page 27)
New modules for the S7-1200
New modules expand the power of the S7-1200 CPU and provide the flexibility to meet your
automation needs:
● New Fail-safe CPUs (https://support.industry.siemens.com/cs/ww/en/view/104547552):
There are two new fail-safe CPUs in conjunction with the S7-1200 V4.2 or later release:
– CPU 1212FC DC/DC/DC (6ES7212-1AF40-0XB0)
– CPU 1212FC DC/DC/Rly (6ES7212-1HF40-0XB0)
● The SM 1238 Energy Meter 480 V AC (6ES7238-5XA32-0XB0)
(https://support.industry.siemens.com/cs/ww/en/view/109483435) supports machine-level
deployment with an S7-1200 CPU V4.1 or later, including the Fail-safe CPUs. It records
over 200 different electrical measurement and energy values and lets you create
transparency about the energy requirements of individual components of a production
plant down to the machine level. Using the measured values provided by the SM 1238
Energy meter module, you can determine energy consumption and power demand.
Exchanging your V3.0 CPU for a V4.2 CPU
If you are replacing an S7-1200 V3.0 CPU with an S7-1200 V4.2 CPU, take note of the
documented differences (Page 1571) in the versions and the required user actions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
35
New features
S7-1200 Programmable controller
36
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3
STEP 7 provides a user-friendly environment to develop, edit, and monitor the logic needed
to control your application, including the tools for managing and configuring all of the devices
in your project, such as controllers and HMI devices. To help you find the information you
need, STEP 7 provides an extensive online help system.
STEP 7 provides standard programming languages for convenience and efficiency in
developing the control program for your application.
● LAD (ladder logic) (Page 199) is a graphical programming language. The representation
is based on circuit diagrams.
● FBD (Function Block Diagram) (Page 200) is a programming language that is based on
the graphical logic symbols used in Boolean algebra.
● SCL (structured control language) (Page 201) is a text-based, high-level programming
language.
When you create a code block, you select the programming language to be used by that
block. Your user program can utilize code blocks created in any or all of the programming
languages.
Note
STEP 7 is the programming and configuration software component of the TIA Portal. The
TIA Portal, in addition to STEP 7, also includes WinCC for designing and executing runtime
process visualization, and includes online help for WinCC as well as STEP 7.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
37
STEP 7 programming software
3.1 System requirements
3.1
System requirements
You must install STEP 7 with Administrator privileges.
Table 3- 1
System requirements
Hardware/software
Requirements
Processor type
Intel® Core™ i5-3320M 3.3 GHz or better
RAM
8 GB
Available hard disk space
2 GB on system drive C:\
Operating systems
You can use STEP 7 with the following operating systems (64bit only):
•
Microsoft Windows 7 Home Premium SP1 or higher (STEP 7
Basic only, not supported for STEP 7 Professional)
•
Microsoft Windows 7 or higher (Professional SP1, Enterprise
SP1, Ultimate SP1)
•
Microsoft Windows 8.1 (STEP 7 Basic only, not supported
for STEP 7 Professional)
•
Microsoft Windows 8.1 (Professional, Enterprise)
•
Microsoft Server 2008 R2 StdE SP1 (STEP 7 Professional
only)
•
Microsoft Server 2012 R2 StdE
Graphics card
32 MB RAM
24-bit color depth
Screen resolution
1920 x 1080 (recommended)
Network
10 Mbit/s Ethernet or faster, for communication between STEP 7
and the CPU
Optical drive
DVD-ROM
S7-1200 Programmable controller
38
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.2 Different views to make the work easier
3.2
Different views to make the work easier
STEP 7 provides a user-friendly environment to develop controller logic, configure HMI
visualization, and setup network communication. To help increase your productivity, STEP 7
provides two different views of the project: a task-oriented set of portals that are organized
on the functionality of the tools (Portal view), or a project-oriented view of the elements within
the project (Project view). Choose which view helps you work most efficiently. With a single
click, you can toggle between the Portal view and the Project view.
Portal view
① Portals for the different tasks
② Tasks for the selected portal
③ Selection panel for the selected
action
④ Changes to the Project view
Project view
① Menus and toolbar
② Project navigator
③ Work area
④ Task cards
⑤ Inspector window
⑥ Changes to the Portal view
⑦ Editor bar
With all of these components in one place, you have easy access to every aspect of your
project. The work area consists of three tabbed views:
● Device view: Displays the device that you have added or selected and its associated
modules
● Network view: Displays the CPUs and network connections in your network
● Topology view: Displays the PROFINET topology of the network including devices,
passive components, ports, interconnections, and port diagnostics
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
39
STEP 7 programming software
3.2 Different views to make the work easier
Each view also enables you to perform configuration tasks. The inspector window shows the
properties and information for the object that you have selected in the work area. As you
select different objects, the inspector window displays the properties that you can configure.
The inspector window includes tabs that allow you to see diagnostic information and other
messages.
By showing all of the editors that are open, the editor bar helps you work more quickly and
efficiently. To toggle between the open editors, simply click the different editor. You can also
arrange two editors to appear together, arranged either vertically or horizontally. This feature
allows you to drag and drop between editors.
The STEP 7 Information System provides extensive online help for all of the configuration,
programming, and monitoring tools of STEP 7. You can refer to it for detailed explanations
beyond what this manual provides.
S7-1200 Programmable controller
40
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.3 Easy-to-use tools
3.3
Easy-to-use tools
3.3.1
Inserting instructions into your user program
STEP 7 provides task cards that contain the instructions for your
program. The instructions are grouped according to function.
To create your program, you drag instructions from the task card
onto a network.
3.3.2
Accessing instructions from the "Favorites" toolbar
STEP 7 provides a "Favorites" toolbar to give you quick access to the instructions that you
frequently use. Simply click the icon for the instruction to insert it into your network!
(For the "Favorites" in the instruction tree, doubleclick the icon.)
You can easily customize the
"Favorites" by adding new instructions.
Simply drag and drop an instruction to the "Favorites".
The instruction is now just a click
away!
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
41
STEP 7 programming software
3.3 Easy-to-use tools
3.3.3
Creating a complex equation with a simple instruction
The Calculate instruction (Page 255) lets you create a math function that operates on multiple input parameters to produce the result, according to the equation that you define.
In the Basic instruction tree, expand the Math functions folder.
Double-click the Calculate instruction to insert the instruction
into your user program.
The unconfigured Calculate instruction provides two input parameters
and an output parameter.
Click the "???" and select the data types for the input and output parameters. (The input and output parameters must all be the same data
type.)
For this example, select the "Real" data type.
Click the "Edit equation" icon to enter the equation.
S7-1200 Programmable controller
42
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.3 Easy-to-use tools
For this example, enter the following equation for scaling a raw analog value. (The "In" and
"Out" designations correspond to the parameters of the Calculate instruction.)
Out value = ((Out high - Out low) / (In high - In low)) * (In value - In low) + Out low
Out
Where:
= ((in4 - in5) / (in2 - in3)) * (in1 - in3) + in5
Out value
(Out)
Scaled output value
In value
(in1)
Analog input value
In high
(in2)
Upper limit for the scaled input value
In low
(in3)
Lower limit for the scaled input value
Out high
(in4)
Upper limit for the scaled output value
Out low
(in5)
Lower limit for the scaled output value
In the "Edit Calculate" box, enter the equation with the parameter names:
OUT = ((in4 - in5) / (in2 - in3)) * (in1 - in3) + in5
When you click "OK", the Calculate
instruction creates the inputs required for the instruction.
Enter the tag names for the values
that correspond to the parameters.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
43
STEP 7 programming software
3.3 Easy-to-use tools
3.3.4
Adding inputs or outputs to a LAD or FBD instruction
Some of the instructions allow you to create additional inputs or outputs.
● To add an input or output, click the "Create" icon or right-click on an input stub for one of
the existing IN or OUT parameters and select the "Insert input" command.
● To remove an input or output, right-click on the stub for one of the existing IN or OUT
parameters (when there are more than the original two inputs) and select the "Delete"
command.
3.3.5
Expandable instructions
Some of the more complex instructions are expandable, displaying only the key inputs and
outputs. To display all the inputs and outputs, click the arrow at the bottom of the instruction.
S7-1200 Programmable controller
44
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.3 Easy-to-use tools
3.3.6
Selecting a version for an instruction
The development and release cycles for certain sets of instructions (such as Modbus, PID
and motion) have created multiple released versions for these instructions. To help ensure
compatibility and migration with older projects, STEP 7 allows you to choose which version
of instruction to insert into your user program.
Click the icon on the instruction tree task card
to enable the headers and columns of the
instruction tree.
To change the version of the instruction, select the appropriate version from the dropdown list.
3.3.7
Modifying the appearance and configuration of STEP 7
You can select a variety of settings, such as the appearance of the interface, language, or
the folder for saving your work.
Select the "Settings" command from the "Options" menu to change these settings.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
45
STEP 7 programming software
3.3 Easy-to-use tools
3.3.8
Dragging and dropping between editors
To help you perform tasks quickly and easily,
STEP 7 allows you to drag and drop elements
from one editor to another. For example, you
can drag an input from the CPU to the address
of an instruction in your user program.
You must zoom in at least 200% to select the
inputs or outputs of the CPU.
Notice that the tag names are displayed not
only in the PLC tag table, but also are displayed on the CPU.
To display two editors at one time, use the
"Split editor" menu commands or buttons in
the toolbar.
To toggle between the editors that have been opened, click the icons in the editor bar.
S7-1200 Programmable controller
46
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.3 Easy-to-use tools
3.3.9
Changing the operating mode of the CPU
The CPU does not have a physical switch for changing the operating mode (STOP or RUN).
Use the "Start CPU" and "Stop CPU" toolbar buttons to change the operating
mode of the CPU.
When you configure the CPU in the device configuration (Page 153), you configure the startup behavior in the properties of the CPU (Page 170).
The "Online and diagnostics" portal also provides an operator panel for changing the
operating mode of the online CPU. To use the CPU operator panel, you must be connected
online to the CPU. The "Online tools" task card displays an operator panel that shows the
operating mode of the online CPU. The operator panel also allows you to change the
operating mode of the online CPU.
Use the button on the operator panel to change the operating mode
(STOP or RUN). The operator panel also provides an MRES button for
resetting the memory.
The color of the RUN/STOP indicator shows the current operating mode of the CPU. Yellow
indicates STOP mode, and green indicates RUN mode.
From the device configuration in STEP 7 (Page 153) you can also configure the default
operating mode on power up of the CPU (Page 87).
Note
You can also change the operating mode of the CPU from the Web server (Page 1001) or
the SIMATIC Automation Tool
(https://support.industry.siemens.com/cs/ww/en/view/98161300).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
47
STEP 7 programming software
3.3 Easy-to-use tools
3.3.10
Changing the call type for a DB
STEP 7 allows you to easily create or change the association of a DB for an instruction or an FB that is in an FB.
• You can switch the association between different DBs.
• You can switch the association between a singleinstance DB and a multi-instance DB.
• You can create an instance DB (if an instance DB is
missing or not available).
You can access the "Change call type" command either
by right-clicking the instruction or FB in the program editor or by selecting the "Block call" command from the
"Options" menu.
The "Call options" dialog allows
you to select a single-instance
or multi-instance DB. You can
also select specific DBs from a
drop-down list of available DBs.
S7-1200 Programmable controller
48
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.3 Easy-to-use tools
3.3.11
Temporarily disconnecting devices from a network
From the network view, you can disconnect individual network devices from the subnet.
Because the configuration of the device is not removed from the project, you can easily
restore the connection to the device.
Right-click the interface port of the network
device and select the "Disconnect from subnet" command from the context menu.
STEP 7 reconfigures the network connections, but does not remove the disconnected device
from the project. While the network connection is deleted, the interface addresses are not
changed.
When you download the new network connections, the CPU must be set to STOP mode.
To reconnect the device, simply create a new network connection to the port of the device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
49
STEP 7 programming software
3.3 Easy-to-use tools
3.3.12
Virtual unplugging of devices from the configuration
STEP 7 provides a storage area for "unplugged" modules. You can drag a module
from the rack to save the configuration of
that module. These unplugged modules
are saved with your project, allowing you
to reinsert the module in the future without
having to reconfigure the parameters.
One use of this feature is for temporary
maintenance. Consider a scenario where
you might be waiting for a replacement
module and plan to temporarily use a different module as a short-term replacement. You could drag the configured
module from the rack to the "Unplugged
modules" and then insert the temporary
module.
S7-1200 Programmable controller
50
System Manual, V4.2, 09/2016, A5E02486680-AK
STEP 7 programming software
3.4 Backward compatibility
3.4
Backward compatibility
STEP 7 V14 supports configuration and programming of the S7-1200 V4.2 CPU and
provides for all of the new features (Page 33).
You can download projects for S7-1200 V4.0 and V4.1 CPUs from STEP 7 (V12 or later) to
an S7-1200 V4.2 CPU. Your configuration and program will be limited to the set of features
and instructions that the previous version of the S7-1200 CPU and your version of STEP 7
supported.
This backwards compatibility makes it possible for you to run programs on the new
S7-1200 V4.2 CPU models that you have previously designed and programmed for older
versions.
WARNING
Risks with copying and pasting program logic from older versions of STEP 7
Copying program logic from an older version of STEP 7 such as STEP 7 V12 into STEP 7
V14 can cause unpredictable behavior in program execution or failures to compile. Different
versions of STEP 7 implement program elements differently. The compiler does not always
detect the differences if you made the changes by pasting from an older version into
STEP 7 V14. Executing unpredictable program logic could result in death or severe
personal injury if you do not correct the program.
When using program logic from a release of STEP 7 earlier than STEP 7 V14, always
upgrade the entire project to STEP 7 14. Then you can copy, cut, paste, and edit program
logic as necessary. In STEP 7 V14, you can open a project from STEP 7 V13 SP1 or later.
STEP 7 then performs the necessary compatibility conversions and upgrades the program
correctly. Such upgrade conversions and corrections are necessary for proper program
compilation and execution. If your project is older than STEP 7 V13 SP1, you must upgrade
the project incrementally to STEP 7 V14 (Page 1571).
You cannot download projects for V1.0, V2.0, or V3.0 S7-1200 CPUs to an S7-1200 V4.2
CPU. See the Device exchange and spare parts compatibility (Page 1571) topic for
guidelines on upgrading older projects to a project that you can download.
Note
Projects with S7-1200 V1.x CPU versions
You cannot open a STEP 7 project that contains S7-1200 V1.x CPUs in STEP 7 V14. In
order to use your existing project, you must use STEP 7 V13 SP1 (with any update) to open
your project and convert the S7-1200 V1.x CPUs to V2.0 or later. You can then use STEP 7
V14 to open the saved project with the converted CPUs.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
51
STEP 7 programming software
3.4 Backward compatibility
S7-1200 Programmable controller
52
System Manual, V4.2, 09/2016, A5E02486680-AK
4
Installation
4.1
Guidelines for installing S7-1200 devices
The S7-1200 equipment is designed to be easy to install. You can install an S7-1200 either
on a panel or on a standard rail, and you can orient the S7-1200 either horizontally or
vertically. The small size of the S7-1200 allows you to make efficient use of space.
Electrical equipment standards classify the SIMATIC S7-1200 system as Open Equipment.
You must install the S7-1200 in a housing, cabinet, or electric control room. You should limit
entry to the housing, cabinet, or electric control room to authorized personnel.
The installation should provide a dry environment for the S7-1200. SELV/PELV circuits are
considered to provide protection against electric shock in dry locations.
The installation should provide the appropriate mechanical strength, flammability protection,
and stability protection that is approved for open equipment in your particular location
category according to applicable electrical and building codes.
Conductive contamination due to dust, moisture, and airborne pollution can cause
operational and electrical faults in the PLC.
If you locate the PLC in an area where conductive contamination may be present, the PLC
must be protected by an enclosure with appropriate protection rating. IP54 is one rating that
is generally used for electronic equipment enclosures in dirty environments and may be
appropriate for your application.
WARNING
Improper installation of the S7-1200 can result in electrical faults or unexpected operation
of machinery.
Electrical faults or unexpected machine operation can result in death, severe personal
injury, and/or property damage.
All instructions for installation and maintenance of a proper operating environment must be
followed to ensure the equipment operates safely.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
53
Installation
4.1 Guidelines for installing S7-1200 devices
Separate the S7-1200 devices from heat, high voltage, and electrical noise
As a general rule for laying out the devices of your system, always separate the devices that
generate high voltage and high electrical noise from the low-voltage, logic-type devices such
as the S7-1200.
When configuring the layout of the S7-1200 inside your panel, consider the heat-generating
devices and locate the electronic-type devices in the cooler areas of your cabinet. Reducing
the exposure to a high-temperature environment will extend the operating life of any
electronic device.
Consider also the routing of the wiring for the devices in the panel. Avoid placing low-voltage
signal wires and communications cables in the same tray with AC power wiring and highenergy, rapidly-switched DC wiring.
Provide adequate clearance for cooling and wiring
S7-1200 devices are designed for natural convection cooling. For proper cooling, you must
provide a clearance of at least 25 mm above and below the devices. Also, allow at least 25
mm of depth between the front of the modules and the inside of the enclosure.
CAUTION
For vertical mounting, the maximum allowable ambient temperature is reduced by 10
degrees C.
Orient a vertically mounted S7-1200 system as shown in the following figure.
Ensure that the S7-1200 system is mounted correctly.
S7-1200 Programmable controller
54
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.1 Guidelines for installing S7-1200 devices
When planning your layout for the S7-1200 system, allow enough clearance for the wiring
and communications cable connections.
①
②
Side view
Horizontal installation
③
④
Vertical installation
Clearance area
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
55
Installation
4.2 Power budget
4.2
Power budget
Your CPU has an internal power supply that provides power for the CPU, the signal
modules, signal board and communication modules and for other 24 V DC user power
requirements.
Refer to the technical specifications (Page 1359) for information about the 5 V DC logic
budget supplied by your CPU and the 5 V DC power requirements of the signal modules,
signal boards, and communication modules. Refer to "Calculating a power budget"
(Page 1555) to determine how much power (or current) the CPU can provide for your
configuration.
The CPU provides a 24 V DC sensor supply that can supply 24 V DC for input points, for
relay coil power on the signal modules, or for other requirements. If your 24 V DC power
requirements exceed the budget of the sensor supply, then you must add an external 24 V
DC power supply to your system. Refer to the technical specifications (Page 1359) for the
24 V DC sensor supply power budget for your particular CPU.
If you require an external 24 V DC power supply, ensure that the power supply is not
connected in parallel with the sensor supply of the CPU. For improved electrical noise
protection, it is recommended that the commons (M) of the different power supplies be
connected.
WARNING
Connecting an external 24 V DC power supply in parallel with the 24 V DC sensor supply
can result in a conflict between the two supplies as each seeks to establish its own
preferred output voltage level
The result of this conflict can be shortened lifetime or immediate failure of one or both
power supplies, with consequent unpredictable operation of the PLC system. Unpredictable
operation could result in death, severe personal injury and/or property damage.
The DC sensor supply and any external power supply should provide power to different
points.
Some of the 24 V DC power input ports in the S7-1200 system are interconnected, with a
common logic circuit connecting multiple M terminals. For example, the following circuits are
interconnected when designated as "not isolated" in the data sheets: the 24 V DC power
supply of the CPU, the power input for the relay coil of an SM, or the power supply for a nonisolated analog input. All non-isolated M terminals must connect to the same external
reference potential.
WARNING
Connecting non-isolated M terminals to different reference potentials will cause unintended
current flows that may cause damage or unpredictable operation in the PLC and any
connected equipment.
Failure to comply with these guidelines could cause damage or unpredictable operation
which could result in death or severe personal injury and/or property damage.
Always ensure that all non-isolated M terminals in an S7-1200 system are connected to the
same reference potential.
S7-1200 Programmable controller
56
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3
Installation and removal procedures
4.3.1
Mounting dimensions for the S7-1200 devices
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
57
Installation
4.3 Installation and removal procedures
Table 4- 1
Mounting dimensions (mm)
S7-1200 Devices
CPU
Signal modules
Width A
(mm)
Width B
(mm)
Width C
(mm)
CPU 1211C and CPU 1212C
90
45
--
CPU 1214C
110
55
--
CPU 1215C
130
65 (top)
Bottom:
C1: 32.5
C2: 65
C3: 32.5
CPU 1217C
150
75
Bottom:
C1: 37.5
C2: 75
C3: 37.5
Digital 8 and 16 point
45
22.5
--
Digital DQ 8 x Relay (Changeover)
70
35
--
Analog 16 point
70
35
--
SM 1238 Energy Meter module
45
22.5
--
CM 1241 RS232, and
CM 1241 RS422/485
30
15
--
TS Adapter
30
15
--
TS Module
30
15
--
Analog 2, 4, and 8 point
Thermocouple 4 and 8 point
RTD 4 point
SM 1278 IO Link-Master
RTD 8 point
Communication
interfaces
CM 1243-5 PROFIBUS master and
CM 1242-5 PROFIBUS slave
CM 1242-2 AS-i Master
CP 1242-7 GPRS V2
CP 1243-7 LTE-EU
CP 1243-1 DNP3
CP 1243-1 IEC
CP 1243-1
CP1243-1 PCC
CP 1243-8 IRC
RF120C
TS (TeleService) Adapter IE Advanced 1
TS (Teleservice) Adapter IE Basic 1
1
Before installing the TS (TeleService) Adapter IE Advanced or IE Basic, you must first connect the
TS Adapter and a TS module. The total width ("width A") is 60 mm.
S7-1200 Programmable controller
58
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
Each CPU, SM, CM, and CP supports mounting on either a DIN rail or on a panel. Use the
DIN rail clips on the module to secure the device on the rail. These clips also snap into an
extended position to provide screw mounting positions to mount the unit directly on a panel.
The interior dimension of the hole for the DIN clips on the device is 4.3 mm.
A 25 mm thermal zone must be provided above and below the unit for free air circulation.
Installing and removing the S7-1200 devices
The CPU can be easily installed on a standard DIN rail or on a panel. DIN rail clips are
provided to secure the device on the DIN rail. The clips also snap into an extended position
to provide a screw mounting position for panel-mounting the unit.
①
②
DIN rail installation
DIN rail clip in latched position
③
④
Panel installation
Clip in extended position for panel mounting
Before you install or remove any electrical device, ensure that the power to that equipment
has been turned off. Also, ensure that the power to any related equipment has been turned
off.
WARNING
Installation or removal of S7-1200 or related equipment with the power applied could cause
electric shock or unexpected operation of equipment.
Failure to disable all power to the S7-1200 and related equipment during installation or
removal procedures could result in death, severe personal injury and/or property damage
due to electric shock or unexpected equipment operation.
Always follow appropriate safety precautions and ensure that power to the S7-1200 is
disabled before attempting to install or remove S7-1200 CPUs or related equipment.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
59
Installation
4.3 Installation and removal procedures
Always ensure that whenever you replace or install an S7-1200 device you use the correct
module or equivalent device.
WARNING
Incorrect installation of an S7-1200 module may cause the program in the S7-1200 to
function unpredictably.
Failure to replace an S7-1200 device with the same model, orientation, or order could result
in death, severe personal injury and/or property damage due to unexpected equipment
operation.
Replace an S7-1200 device with the same model, and be sure to orient and position it
correctly.
WARNING
Do not disconnect equipment when a flammable or combustible atmosphere is present.
Disconnection of equipment when a flammable or combustible atmosphere is present may
cause a fire or explosion which could result in death, serious injury and/or property
damage.
Always follow appropriate safety precautions when a flammable or combustible atmosphere
is present.
Note
Electrostatic discharge can damage the device or the receptacle on the CPU.
Make contact with a grounded conductive pad and/or wear a grounded wrist strap whenever
you handle the device.
S7-1200 Programmable controller
60
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.2
Installing and removing the CPU
You can install the CPU on a panel or on a DIN rail.
Note
Attach any communication modules to the CPU and install the assembly as a unit. Install
signal modules separately after the CPU has been installed.
Consider the following when installing the units on the DIN rail or on a panel:
● For DIN rail mounting, make sure the upper DIN rail clip is in the latched (inner) position
and that the lower DIN rail clip is in the extended position for the CPU and attached CMs.
● After installing the devices on the DIN rail, move the lower DIN rail clips to the latched
position to lock the devices on the DIN rail.
● For panel mounting, make sure the DIN rail clips are pushed to the extended position.
To install the CPU on a panel, follow these steps:
1. Locate, drill, and tap the mounting holes (M4), using the dimensions shown in table,
Mounting dimensions (mm) (Page 57).
2. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
3. Extend the mounting clips from the module. Make sure the DIN rail clips on the top and
bottom of the CPU are in the extended position.
4. Secure the module to the panel, using a Pan Head M4 screw with spring and flat washer.
Do not use a flat head screw.
Note
The type of screw will be determined by the material upon which it is mounted. You
should apply appropriate torque until the spring washer becomes flat. Avoid applying
excessive torque to the mounting screws. Do not use a flat head screw.
Note
Using DIN rail stops could be helpful if your CPU is in an environment with high vibration
potential or if the CPU has been installed vertically. Use an end bracket (8WA1808 or
8WA1805) on the DIN rail to ensure that the modules remain connected. If your system is
in a high-vibration environment, then panel-mounting the CPU will provide a greater level
of vibration protection.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
61
Installation
4.3 Installation and removal procedures
Table 4- 2
Task
Installing the CPU on a DIN rail
Procedure
1. Install the DIN rail. Secure the rail to the mounting panel every 75 mm.
2. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical
power.
3. Hook the CPU over the top of the DIN rail.
4. Pull out the DIN rail clip on the bottom of the CPU to allow the CPU to fit over the rail.
5. Rotate the CPU down into position on the rail.
6. Push in the clips to latch the CPU to the rail.
Table 4- 3
Task
Removing the CPU from a DIN rail
Procedure
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
2. Disconnect the I/O connectors, wiring, and cables from the
CPU (Page 68).
3. Remove the CPU and any attached communication modules
as a unit. All signal modules should remain installed.
4. If an SM is connected to the CPU, retract the bus connector:
–
Place a screwdriver beside the tab on the top of the signal module.
–
Press down to disengage the connector from the CPU.
–
Slide the tab fully to the right.
5. Remove the CPU:
–
Pull out the DIN rail clip to release the CPU from the rail.
–
Rotate the CPU up and off the rail, and remove the CPU
from the system.
S7-1200 Programmable controller
62
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.3
Table 4- 4
Installing and removing an SB, CB, or BB
Installing an SB, CB, or BB 1297
Task
Procedure
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
2. Remove the top and bottom terminal block covers from the CPU.
3. Place a screwdriver into the slot on top of the CPU at the rear of
the cover.
4. Gently pry the cover straight up and remove it from the CPU.
5. Place the module straight down into its mounting position in the
top of the CPU.
6. Firmly press the module into position until it snaps into place.
7. Replace the terminal block covers.
Table 4- 5
Removing an SB, CB or BB 1297
Task
Procedure
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
2. Remove the top and bottom terminal block covers from the CPU.
3. Remove the signal board connector (if installed) by gently disengaging with a screwdriver.
4. Place a screwdriver into the slot on top of the module.
5. Gently pry the module up to disengage it from the CPU.
6. Without using a screwdriver, remove the module straight up from
its mounting position in the top of the CPU.
7. Replace the cover onto the CPU.
8. Replace the terminal block covers.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
63
Installation
4.3 Installation and removal procedures
Installing or replacing the battery in the BB 1297 battery board
The BB 1297 requires battery type CR1025. The battery is not included with the BB 1297
and must be purchased. To install or replace the battery, follow these steps:
1. In the BB 1297, install a new battery with the positive side of the battery on top, and the
negative side next to the printed wiring board.
2. The BB 1297 is ready to be installed in the CPU. Follow the installation directions above
to install the BB 1297.
To replace the battery in the BB 1297:
1. Remove the BB 1297 from the CPU following the removal directions above.
2. Carefully remove the old battery using a small screwdriver. Push the battery out from
under the clip.
3. Install a new CR1025 replacement battery with the positive side of the battery on top and
the negative side next to the printed wiring board.
4. Re-install the BB 1297 battery board following the installation directions above.
WARNING
Installing an unspecified battery in the BB 1297, or otherwise connecting an unspecified
battery to the circuit can result in fire or component damage and unpredictable operation of
machinery.
Fire or unpredictable operation of machinery can result in death, severe personal injury, or
property damage.
Use only the specified CR1025 battery for backup of the Real-time clock.
S7-1200 Programmable controller
64
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.4
Table 4- 6
Installing and removing an SM
Installing an SM
Task
Procedure
Install your SM after installing the CPU.
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
2. Remove the cover for the connector from the right side of the
CPU:
–
Insert a screwdriver into the slot above the cover.
–
Gently pry the cover out at its top and remove the cover.
3. Retain the cover for reuse.
Connect the SM to the CPU:
1. Position the SM beside the CPU.
2. Hook the SM over the top of the DIN rail.
3. Pull out the bottom DIN rail clip to allow the SM to fit over the
rail.
4. Rotate the SM down into position beside the CPU and push
the bottom clip in to latch the SM onto the rail.
Extending the bus connector makes both mechanical and electrical connections for the SM.
1. Place a screwdriver beside the tab on the top of the SM.
2. Slide the tab fully to the left to extend the bus connector into
the CPU.
Follow the same procedure to install a signal module to a signal
module.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
65
Installation
4.3 Installation and removal procedures
Table 4- 7
Task
Removing an SM
Procedure
You can remove any SM without removing the CPU or other SMs in place.
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical power.
2. Remove the I/O connectors and wiring from the SM (Page 68).
3. Retract the bus connector.
–
Place a screwdriver beside the tab on the top of the SM.
–
Press down to disengage the connector from the CPU.
– Slide the tab fully to the right.
If there is another SM to the right, repeat this procedure for that SM.
Remove the SM:
1. Pull out the bottom DIN rail clip to release the SM from the rail.
2. Rotate the SM up and off the rail. Remove the SM from the system.
3. If required, cover the bus connector on the CPU to avoid contamination.
Follow the same procedure to remove a signal module from a signal module.
S7-1200 Programmable controller
66
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.5
Installing and removing a CM or CP
Attach any communication modules to the CPU and install the assembly as a unit, as shown
in Installing and removing the CPU (Page 61).
Table 4- 8
Installing a CM or CP
Task
Procedure
1. Ensure that the CPU and all S7-1200 equipment are
disconnected from electrical power.
2. Attach the CM to the CPU before installing the assembly
as a unit to the DIN rail or panel.
3. Remove the bus cover from the left side of the CPU:
–
Insert a screwdriver into the slot above the bus cover.
–
Gently pry out the cover at its top.
4. Remove the bus cover. Retain the cover for reuse.
5. Connect the CM or CP to the CPU:
–
Align the bus connector and the posts of the CM with
the holes of the CPU
–
Firmly press the units together until the posts snap into place.
6. Install the CPU and CP on a DIN rail or panel.
Table 4- 9
Removing a CM or CP
Task
Procedure
Remove the CPU and CM as a unit from the DIN rail or panel.
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical
power.
2. Remove the I/O connectors and all wiring and cables from the CPU and CMs.
3. For DIN rail mounting, move the lower DIN rail clips on the CPU and CMs to the
extended position.
4. Remove the CPU and CMs from the DIN rail or panel.
5. Grasp the CPU and CMs firmly and pull apart.
NOTICE
Separate modules without using a tool.
Do not use a tool to separate the modules because this can damage the units.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
67
Installation
4.3 Installation and removal procedures
4.3.6
Removing and reinstalling the S7-1200 terminal block connector
The CPU, SB and SM modules provide removable connectors to make connecting the wiring
easy.
Table 4- 10
Task
Removing the connector
Procedure
Prepare the system for terminal block connector removal by removing the power from
the CPU and opening the cover above the connector.
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical
power.
2. Inspect the top of the connector and locate the slot for the tip of the screwdriver.
3. Insert a screwdriver into the slot.
4. Gently pry the top of the connector away from the CPU. The connector will release
with a snap.
5. Grasp the connector and remove it from the CPU.
Table 4- 11
Task
Installing the connector
Procedure
Prepare the components for terminal block installation by removing power from the
CPU and opening the cover for connector.
1. Ensure that the CPU and all S7-1200 equipment are disconnected from electrical
power.
2. Align the connector with the pins on the unit.
3. Align the wiring edge of the connector inside the rim of the connector base.
4. Press firmly down and rotate the connector until it snaps into place.
Check carefully to ensure that the connector is properly aligned and fully engaged.
S7-1200 Programmable controller
68
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.7
Installing and removing the expansion cable
The S7-1200 expansion cable provides additional flexibility in configuring the layout of your
S7-1200 system. Only one expansion cable is allowed per CPU system. You install the
expansion cable either between the CPU and the first SM, or between any two SMs.
Table 4- 12
Installing and removing the male connector of the expansion cable
Task
Procedure
To install the male connector:
1. Ensure that the CPU and all S7-1200 equipment are
disconnected from electrical power.
2. Push the connector into the bus connector on the right
side of the signal module or CPU.
To remove the male connector:
1. Ensure that the CPU and all S7-1200 equipment are
disconnected from electrical power.
2. Pull out the male connector to release it from the signal
module or CPU.
Table 4- 13
Installing the female connector of the expansion cable
Task
Procedure
1. Ensure that the CPU and all S7-1200 equipment are
disconnected from electrical power.
2. Place the female connector to the bus connector on the
left side of the signal module.
3. Slip the hook extension of the female connector into the
housing at the bus connector and press down slightly
to engage the hook.
4. Lock the connector into place:
–
Place a screwdriver beside the tab on the top of the
signal module.
– Slide the tab fully to the left.
To engage the connector, you must slide the connector tab
all the way to the left. The connector tab must be locked
into place.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
69
Installation
4.3 Installation and removal procedures
Table 4- 14
Removing the female connector of the expansion cable
Task
Procedure
1. Ensure that the CPU and all S7-1200 equipment are
disconnected from electrical power.
2. Unlock the connector:
–
Place a screwdriver beside the tab on the top of the
signal module.
–
Press down slightly and slide the tab fully to the
right.
3. Lift the connector up slightly to disengage the hook
extension.
4. Remove the female connector.
Note
Installing the expansion cable in a vibration environment
If the expansion cable is connected to modules that move, or are not firmly fixed, the cable
male end snap-on connection can gradually become loose.
Use a cable tie to fix the male end cable on the DIN-rail (or other place) to provide extra
strain relief.
Avoid using excessive force when you pull the cable during installation. Ensure the cablemodule connection is in the correct position once installation is complete.
S7-1200 Programmable controller
70
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.8
TS (TeleService) adapter
4.3.8.1
Connecting the TeleService adapter
Before installing the TS (TeleService) Adapter IE Basic or TS (TeleService) Adapter IE
Advanced, you must first connect the TS Adapter and a TS module.
Available TS modules:
● TS module RS232
● TS module Modem
● TS module GSM
● TS module ISDN
Note
The TS module can be damaged if you touch the contacts of the plug connector ④ of the
TS module.
Follow ESD guidelines in order to avoid damaging the TS module through electrostatic
discharge. Before connecting a TS module and TS Adapter, make sure that both are in an
idle state.
①
②
③
TS module
TS Adapter
Elements
④
⑤
⑥
Plug connector from the TS module
Cannot be opened
Ethernet port
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
71
Installation
4.3 Installation and removal procedures
Note
Before connecting a TS module and TS adapter basic unit, ensure that the contact pins ④
are not bent.
When connecting, ensure that the male connector and guide pins are positioned correctly.
Only connect a TS module into the TS adapter. Do not force a connection of the TS adapter
to a different device, such as an S7-1200 CPU. Do not change the mechanical construction
of the connector, and do not remove or damage the guide pins.
S7-1200 Programmable controller
72
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.8.2
Installing the SIM card
Locate the SIM card slot on the underside of the TS module GSM.
Note
The SIM card may only be removed or inserted if the TS module GSM is de-energized.
Table 4- 15
Installing the SIM card
Task
Procedure
Use a sharp object to press the eject
button of the SIM card tray (in the
direction of the arrow) and remove the
SIM card tray.
Place the SIM card in the SIM card
tray as shown and put the SIM card
tray back into its slot.
① TS Module GSM
② SIM card
③ SIM card tray
Note
Ensure that the SIM card is correctly oriented in the card tray. Otherwise, the SIM card will
not make connection with the module, and the eject button may not remove the card tray.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
73
Installation
4.3 Installation and removal procedures
4.3.8.3
Installing the TS adapter unit on a DIN rail
Prerequisites: You must have connected the TS Adapter and a TS module together, and the
DIN rail must have been installed.
Note
If you install the TS unit vertically or in high-vibration environment, the TS module can
become disconnected from the TS Adapter. Use an end bracket 8WA1808 on the DIN rail to
ensure that the modules remain connected.
Table 4- 16
Installing and removing the TS Adapter
Task
Procedure
Installation:
1. Hook the TS Adapter with attached TS module ①
on the DIN rail ②.
2. Rotate the unit back until it engages.
3. Push in the DIN rail clip on each module to attach
each module to the rail.
Removal:
1. Remove the analog cable and Ethernet cable from
the underside of the TS Adapter.
2. Remove power from the TS Adapter.
3. Use a screwdriver to disengage the rail clips on
both modules.
4. Rotate the unit upwards to remove the unit from the
DIN rail.
WARNING
Safety requirements for installing or removing the TS Adapter.
Before you remove power from the unit, disconnect the grounding of the TS Adapter by
removing the analog cable and Ethernet cable. Failure to observe this precaution could
result in death, severe personal injury and/or property damage due to unexpected
equipment operation.
Always follow these requirements when installing or removing the TS Adapter.
S7-1200 Programmable controller
74
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.3 Installation and removal procedures
4.3.8.4
Installing the TS adapter on a panel
Prerequisites: You must have connected the TS Adapter and TS module.
1. Move the attachment slider ① to the backside of the TS Adapter and TS module in the
direction of the arrow until it engages.
2. Screw the TS Adapter and TS module to the position marked with ② to the designated
assembly wall.
The following illustration shows the TS Adapter from behind, with the attachment sliders ①
in both positions:
①
②
Attachment slider
Drill holes for wall mounting
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
75
Installation
4.4 Wiring guidelines
4.4
Wiring guidelines
Proper grounding and wiring of all electrical equipment is important to help ensure the
optimum operation of your system and to provide additional electrical noise protection for
your application and the S7-1200. Refer to the technical specifications (Page 1359) for the
S7-1200 wiring diagrams.
Prerequisites
Before you ground or install wiring to any electrical device, ensure that the power to that
equipment has been turned off. Also, ensure that the power to any related equipment has
been turned off.
Ensure that you follow all applicable electrical codes when wiring the S7-1200 and related
equipment. Install and operate all equipment according to all applicable national and local
standards. Contact your local authorities to determine which codes and standards apply to
your specific case.
WARNING
Installation or wiring the S7-1200 or related equipment with power applied could cause
electric shock or unexpected operation of equipment.
Failure to disable all power to the S7-1200 and related equipment during installation or
removal procedures could result in death, severe personal injury, and/or damage due to
electric shock or unexpected equipment operation.
Always follow appropriate safety precautions and ensure that power to the S7-1200 is
disabled before attempting to install or remove the S7-1200 or related equipment.
Always take safety into consideration as you design the grounding and wiring of your S71200 system. Electronic control devices, such as the S7-1200, can fail and can cause
unexpected operation of the equipment that is being controlled or monitored. For this reason,
you should implement safeguards that are independent of the S7-1200 to protect against
possible personal injury or equipment damage.
WARNING
Control devices can fail in an unsafe condition, resulting in unexpected operation of
controlled equipment.
Such unexpected operations could result in death, severe personal injury and/or property
damage.
Use an emergency stop function, electromechanical overrides, or other redundant
safeguards that are independent of the S7-1200.
S7-1200 Programmable controller
76
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.4 Wiring guidelines
Guidelines for isolation
S7-1200 AC power supply boundaries and I/O boundaries to AC circuits have been designed
and approved to provide safe separation between AC line voltages and low voltage circuits.
These boundaries include double or reinforced insulation, or basic plus supplementary
insulation, according to various standards. Components which cross these boundaries such
as optical couplers, capacitors, transformers, and relays have been approved as providing
safe separation. Only circuits rated for AC line voltage include safety isolation to other
circuits. Isolation boundaries between 24 V DC circuits are functional only, and you should
not depend on these boundaries for safety.
The sensor supply output, communications circuits, and internal logic circuits of an S7-1200
with included AC power supply are sourced as SELV (safety extra-low voltage) according to
EN 61131-2.
To maintain the safe character of the S7-1200 low voltage circuits, external connections to
communications ports, analog circuits, and all 24 V DC nominal power supply and I/O
circuits must be powered from approved sources that meet the requirements of SELV,
PELV, Class 2, Limited Voltage, or Limited Power according to various standards.
WARNING
Use of non-isolated or single insulation supplies to supply low voltage circuits from an AC
line can result in hazardous voltages appearing on circuits that are expected to be touch
safe, such as communications circuits and low voltage sensor wiring.
Such unexpected high voltages could cause electric shock resulting in death, severe
personal injury and/or property damage.
Only use high voltage to low voltage power converters that are approved as sources of
touch safe, limited voltage circuits.
Guidelines for grounding the S7-1200
The best way to ground your application is to ensure that all the common and ground
connections of your S7-1200 and related equipment are grounded to a single point. This
single point should be connected directly to the earth ground for your system.
All ground wires should be as short as possible and should use a large wire size, such as 2
mm2 (14 AWG).
When locating grounds, consider safety-grounding requirements and the proper operation of
protective interrupting devices.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
77
Installation
4.4 Wiring guidelines
Guidelines for wiring the S7-1200
When designing the wiring for your S7-1200, provide a single disconnect switch that
simultaneously removes power from the S7-1200 CPU power supply, from all input circuits,
and from all output circuits. Provide over-current protection, such as a fuse or circuit breaker,
to limit fault currents on supply wiring. Consider providing additional protection by placing a
fuse or other current limit in each output circuit.
Install appropriate surge suppression devices for any wiring that could be subject to lightning
surges. For more information, see Surge immunity (Page 1359) in the General technical
specifications section.
Avoid placing low-voltage signal wires and communications cables in the same wire tray with
AC wires and high-energy, rapidly switched DC wires. Always route wires in pairs, with the
neutral or common wire paired with the hot or signal-carrying wire.
Use the shortest wire possible and ensure that the wire is sized properly to carry the required
current.
Wire and cable should have a temperature rating 30 °C higher than the ambient temperature
around the S7-1200 (for example, a minimum of 85 °C-rated conductors for 55 °C ambient
temperature). You should determine other wiring type and material requirements from the
specific electrical circuit ratings and your installation environment.
Use shielded wires for optimum protection against electrical noise. Typically, grounding the
shield at the S7-1200 gives the best results. You should ground communication cable
shields to S7-1200 communication connector shells using connectors that engage the cable
shield, or by bonding the communication cable shields to a separate ground. You should
ground other cable shields using clamps or copper tape around the shield to provide a high
surface area connection to the grounding point.
When wiring input circuits that are powered by an external power supply, include an
overcurrent protection device in that circuit. External protection is not necessary for circuits
that are powered by the 24 V DC sensor supply from the S7-1200 because the sensor
supply is already current-limited.
All S7-1200 modules have removable connectors for user wiring. To prevent loose
connections, ensure that the connector is seated securely and that the wire is installed
securely into the connector.
To help prevent unwanted current flows in your installation, the S7-1200 provides isolation
boundaries at certain points. When you plan the wiring for your system, you should consider
these isolation boundaries. Refer to the technical specifications (Page 1425) for the amount
of isolation provided and the location of the isolation boundaries. Circuits rated for AC line
voltage include safety isolation to other circuits. Isolation boundaries between 24 V DC
circuits are functional only, and you should not depend on these boundaries for safety.
S7-1200 Programmable controller
78
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.4 Wiring guidelines
A summary of Wiring rules for the S7-1200 CPUs, SMs and SBs is shown below:
Table 4- 17
Wiring rules for S7-1200 CPUs, SMs, and SBs
Wiring rules for...
CPU and SM connector
Connectible conductor
cross-sections for standard wires
2 mm2 to 0.3 mm2 (14 AWG to 22 1.3 mm2 to 0.3 mm2 (16 AWG to 22
AWG)
AWG)
SB connector
Number of wires per connection
1 or combination of 2 wires up to
2 mm2 (total)
Wire strip length
6.4 mm
6.3 to 7 mm
Tightening torque* (maximum)
0.56 N-m (5 inch-pounds)
0.33 N-m (3 inch-pounds)
Tool
2.5 to 3.0 mm flathead screwdriver
2.0 to 2.5 mm flathead screwdriver
1 or combination of 2 wires up to 1.3
mm2 (total)
* To avoid damaging the connector, be careful that you do not over-tighten the screws.
Note
Ferrules or end sleeves on stranded conductors reduce the risk of stray strands causing
short circuits. Ferrules longer than the recommended strip length should include an
insulating collar to prevent shorts due to side movement of conductors. Cross-sectional area
limits for bare conductors also apply to ferrules.
See also
Technical specifications (Page 1359)
Guidelines for lamp loads
Lamp loads are damaging to relay contacts because of the high turn-on surge current. This
surge current will nominally be 10 to 15 times the steady state current for a Tungsten lamp.
A replaceable interposing relay or surge limiter is recommended for lamp loads that will be
switched a large number of times during the lifetime of the application.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
79
Installation
4.4 Wiring guidelines
Guidelines for inductive loads
Use suppressor circuits with inductive loads to limit the voltage rise when a control output
turns off. Suppressor circuits protect your outputs from premature failure caused by the high
voltage transient that occurs when current flow through an inductive load is interrupted.
In addition, suppressor circuits limit the electrical noise generated when switching inductive
loads. High frequency noise from poorly suppressed inductive loads can disrupt the
operation of the PLC. Placing an external suppressor circuit so that it is electrically across
the load and physically located near the load is the most effective way to reduce electrical
noise.
S7-1200 DC outputs include internal suppressor circuits that are adequate for inductive
loads in most applications. Since S7-1200 relay output contacts can be used to switch either
a DC or an AC load, internal protection is not provided.
A good suppressor solution is to use contactors and other inductive loads for which the
manufacturer provides suppressor circuits integrated in the load device, or as an optional
accessory. However, some manufacturer provided suppressor circuits may be inadequate
for your application. An additional suppressor circuit may be necessary for optimal noise
reduction and contact life.
For AC loads, a metal oxide varistor (MOV) or other voltage clamping device may be used
with a parallel RC circuit, but is not as effective when used alone. An MOV suppressor with
no parallel RC circuit often results in significant high frequency noise up to the clamp
voltage.
A well-controlled turn-off transient will have a ring frequency of no more than 10 kHz, with
less than 1 kHz preferred. Peak voltage for AC lines should be within +/- 1200 V of ground.
Negative peak voltage for DC loads using the PLC internal suppression will be ~40 V below
the 24 V DC supply voltage. External suppression should limit the transient to within 36 V of
the supply to unload the internal suppression.
Note
The effectiveness of a suppressor circuit depends on the application and must be verified for
your particular usage. Ensure that all components are correctly rated and use an
oscilloscope to observe the turn-off transient.
S7-1200 Programmable controller
80
System Manual, V4.2, 09/2016, A5E02486680-AK
Installation
4.4 Wiring guidelines
Typical suppressor circuit for DC or relay outputs that switch DC inductive loads
In most applications, the addition of a diode (A)
across a DC inductive load is suitable, but if your
application requires faster turn-off times, then the
addition of a zener diode (B) is recommended. Be
sure to size your zener diode properly for the amount
of current in your output circuit.
① 1N4001 diode or equivalent
② 8.2 V Zener (DC outputs),
36 V Zener (Relay outputs)
③ Output point
④ M, 24 V reference
Typical suppressor circuit for relay outputs that switch AC inductive loads
Ensure that the working voltage of the metal oxide
varistor (MOV) is at least 20% greater than the nominal line voltage.
① See table for C value
② See table for R value
③ Output point
Choose pulse-rated, non-inductive resistors, and
capacitors recommended for pulse applications (typically metal film). Verify the components meet average power, peak power, and peak voltage
requirements.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
81
Installation
4.4 Wiring guidelines
If you design your own suppressor circuit, the following table suggests resistor and capacitor
values for a range of AC loads. These values are based on calculations with ideal
component parameters. I rms in the table refers to the steady-state current of the load when
fully ON.
Table 4- 18
AC suppressor circuit resistor and capacitor values
Inductive load
I rms
230 V AC
Suppressor values
120 V AC
Resistor
Capacitor
Amps
VA
VA
Ω
W (power rating)
nF
0.02
4.6
2.4
15000
0.1
15
0.05
11.5
6
5600
0.25
470
0.1
23
12
2700
0.5
100
0.2
46
24
1500
1
150
0.5
115
60
560
2.5
470
1
230
120
270
5
1000
2
460
240
150
10
1500
Conditions satisfied by the table values:
Maximum turn-off transition step < 500 V
Resistor peak voltage < 500 V
Capacitor peak voltage < 1250 V
Suppressor current < 8% of load current (50 Hz)
Suppressor current < 11% of load current (60 Hz)
Capacitor dV/dt < 2 V/μs
Capacitor pulse dissipation : ∫(dv/dt)2 dt < 10000 V2/μs
Resonant frequency < 300 Hz
Resistor power for 2 Hz max switching frequency
Power factor of 0.3 assumed for typical inductive load
Guidelines for differential inputs and outputs
Differential inputs and outputs behave differently than standard inputs and outputs. There
are two pins per differential input and output. Determining whether a differential input or
output is on or off requires that you measure the voltage difference between these two pins.
See the detailed specifications for the CPU 1217C in Appendix A (Page 1425).
S7-1200 Programmable controller
82
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1
5
Execution of the user program
The CPU supports the following types of code blocks that allow you to create an efficient
structure for your user program:
● Organization blocks (OBs) define the structure of the program. Some OBs have
predefined behavior and start events, but you can also create OBs with custom start
events.
● Functions (FCs) and function blocks (FBs) contain the program code that corresponds to
specific tasks or combinations of parameters. Each FC or FB provides a set of input and
output parameters for sharing data with the calling block. An FB also uses an associated
data block (called an instance DB) to maintain the data values for that instance of the FB
call. You can call an FB multiple times, each time with a unique instance DB. Calls to the
same FB with different instance DBs do not affect the data values in any of the other
instance DBs.
● Data blocks (DBs) store data that can be used by the program blocks.
Execution of the user program begins with one or more optional startup organization blocks
(OBs) which execute once upon entering RUN mode, followed by one or more program cycle
OBs that execute cyclically. You can also associate an OB with an interrupt event, which can
be either a standard event or an error event. These OBs execute whenever the
corresponding standard or error event occurs.
A function (FC) or a function block (FB) is a block of program code that can be called from
an OB or from another FC or FB, down to the following nesting depths:
● 16 from the program cycle or startup OB
● 6 from any interrupt event OB
FCs are not associated with any particular data block (DB). FBs are tied directly to a DB and
use the DB for passing parameters and storing interim values and results.
The size of the user program, data, and configuration is limited by the available load memory
and work memory in the CPU. There is no specific limit to the number of each individual OB,
FC, FB and DB block. However, the total number of blocks is limited to 1024.
Each cycle includes writing the outputs, reading the inputs, executing the user program
instructions, and performing background processing. The cycle is referred to as a scan cycle
or scan.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
83
PLC concepts
5.1 Execution of the user program
Your S7-1200 automation solution can consist of a central rack with the S7-1200 CPU and
additional modules. The term "central rack" refers to either the rail or panel installation of the
CPU and associated modules. The modules (SM, SB, BB, CB, CM or CP) are detected and
logged in only upon powerup.
● Inserting or removing a module in the central rack under power (hot) is not supported.
Never insert or remove a module from the central rack when the CPU has power.
WARNING
Safety requirements for inserting or removing modules
Insertion or removal of a module (SM, SB, BB, CD, CM or CP) from the central rack
when the CPU has power could cause unpredictable behavior, resulting in damage to
equipment and/or injury to personnel.
Always remove power from the CPU and central rack and follow appropriate safety
precautions before inserting or removing a module from the central rack.
● You can insert or remove a SIMATIC memory card while the CPU is under power.
However, inserting or removing a memory card when the CPU is in RUN mode causes
the CPU to go to STOP mode.
NOTICE
Risks with removing memory card when CPU is in RUN mode.
Insertion or removal of a memory card when the CPU is in RUN mode causes the CPU
to go to STOP, which might result in damage to the equipment or the process being
controlled.
Whenever you insert or remove a memory card, the CPU immediately goes to STOP
mode. Before inserting or removing a memory card, always ensure that the CPU is not
actively controlling a machine or process. Always install an emergency stop circuit for
your application or process.
● If you insert or remove a module in a distributed I/O rack (AS-i, PROFINET, or
PROFIBUS) when the CPU is in RUN mode, the CPU generates an entry in the
diagnostics buffer, executes the pull or plug of modules OB if present, and by default
remains in RUN mode.
S7-1200 Programmable controller
84
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
Process image update and process image partitions
The CPU updates local digital and analog I/O points synchronously with the scan cycle using
an internal memory area called the process image. The process image contains a snapshot
of the physical inputs and outputs (the physical I/O points on the CPU, signal board, and
signal modules).
You can configure I/O points to be updated in the process image every scan cycle or when a
specific event interrupt occurs. You can also configure an I/O point to be excluded from
process image updates. For example, your process might only need certain data values
when an event such as a hardware interrupt occurs. By configuring the process image
update for these I/O points to be associated with a partition that you assign to a hardware
interrupt OB, you avoid having the CPU update data values unnecessarily every scan cycle
when your process does not need a continual update.
For I/O that is updated every scan cycle, the CPU performs the following tasks during each
scan cycle:
● The CPU writes the outputs from the process image output area to the physical outputs.
● The CPU reads the physical inputs just prior to the execution of the user program and
stores the input values in the process image input area. These values thus remain
consistent throughout the execution of the user instructions.
● The CPU executes the logic of the user instructions and updates the output values in the
process image output area instead of writing to the actual physical outputs.
This process provides consistent logic through the execution of the user instructions for a
given cycle and prevents the flickering of physical output points that might change state
multiple times in the process image output area.
For controlling whether your process updates I/O points automatically on every scan cycle,
or upon the triggering of events, the S7-1200 provides five process image partitions. The first
process image partition, PIP0, is designated for I/O that is to be automatically updated every
scan cycle, and is the default assignment. You can use the remaining four partitions, PIP1,
PIP2, PIP3, and PIP4 for assigning I/O process image updates to various interrupt events.
You assign I/O to process image partitions in Device Configuration and you assign process
image partitions to interrupt events when you create interrupt OBs (Page 188) or edit OB
properties (Page 188).
By default, when you insert a module in the device view, STEP 7 sets its I/O process image
update to "Automatic update". For I/O configured for "Automatic update", the CPU handles
the data exchange between the module and the process image area automatically during
every scan cycle.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
85
PLC concepts
5.1 Execution of the user program
To assign digital or analog points to a process image partition, or to exclude I/O points from
process image updates, follow these steps:
1. View the Properties tab for the appropriate device in Device configuration.
2. Expand the selections under "General" as necessary to locate the desired I/O points.
3. Select "I/O addresses".
4. Optionally select a specific OB from the "Organization block" drop-down list.
5. From the "Process image" drop-down list, change "Automatic update" to "PIP1", "PIP2",
"PIP3", "PIP4" or "None". A selection of "None" means that you can only read from and
write to this I/O using immediate instructions. To add the points back to the process
image automatic update, change this selection back to "Automatic update".
You can immediately read physical input values and immediately write physical output
values when an instruction executes. An immediate read accesses the current state of the
physical input and does not update the process image input area, regardless of whether the
point is configured to be stored in the process image. An immediate write to the physical
output updates both the process image output area (if the point is configured to be stored in
the process image) and the physical output point. Append the suffix ":P" to the I/O address if
you want the program to immediately access I/O data directly from the physical point instead
of using the process image.
Note
Use of process image partitions
If you assign I/O to one of the process image partitions PIP1 - PIP4, and do not assign an
OB to that partition, then the CPU never updates that I/O to or from the process image.
Assigning I/O to a PIP that does not have a corresponding OB assignment, is the same as
assigning the process image to "None". You can read the I/O directly from the physical I/O
with an immediate read instruction, or write to the physical I/O with an immediate write
instruction. The CPU does not update the process image.
The CPU supports distributed I/O for PROFINET, PROFIBUS, and AS-i networks
(Page 799).
S7-1200 Programmable controller
86
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.1
Operating modes of the CPU
The CPU has three modes of operation: STOP mode, STARTUP mode, and RUN mode.
Status LEDs on the front of the CPU indicate the current mode of operation.
● In STOP mode, the CPU is not executing the program. You can download a project.
● In STARTUP mode, the startup OBs (if present) execute once. The CPU does not
process interrupt events during the startup mode.
● In RUN mode, the program cycle OBs execute repeatedly. Interrupt events can occur and
the corresponding interrupt event OBs can execute at any point within the RUN mode.
You can download some parts of a project in RUN mode (Page 1335).
The CPU supports a warm restart for entering the RUN mode. Warm restart does not include
a memory reset. The CPU initializes all non-retentive system and user data at warm restart,
and retains the values of all retentive user data.
A memory reset clears all work memory, clears retentive and non-retentive memory areas,
copies load memory to work memory, and sets outputs to the configured "Reaction to CPU
STOP". A memory reset does not clear the diagnostics buffer or the permanently saved
values of the IP address.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
87
PLC concepts
5.1 Execution of the user program
You can configure the "startup after POWER ON" setting of the CPU. This configuration item
appears under the "Device configuration" for the CPU under "Startup". Upon powering up,
the CPU performs a sequence of power-up diagnostic checks and system initialization.
During system initialization the CPU deletes all non-retentive bit (M) memory and resets all
non-retentive DB contents to the initial values from load memory. The CPU retains retentive
bit (M) memory and retentive DB contents and then enters the appropriate operating mode.
Certain detected errors prevent the CPU from entering the RUN mode. The CPU supports
the following configuration choices:
● No restart (stay in STOP mode)
● Warm restart - RUN
● Warm restart - mode prior to POWER OFF
NOTICE
Repairable faults can cause the CPU to enter STOP mode.
The CPU can enter STOP mode due to repairable faults, such as failure of a
replaceable signal module, or temporary faults, such as power line disturbance or erratic
power up event. Such conditions could result in property damage.
If you have configured the CPU to "Warm restart - mode prior to POWER OFF", the
CPU goes to the operating mode it was in prior to the loss of power or fault. If the CPU
was in STOP mode at the time of power loss or fault, the CPU goes to STOP mode on
power up and stays in STOP mode until it receives a command to go to RUN mode. If
the CPU was in RUN mode at the time of power loss or fault, the CPU goes to RUN
mode on the next power up providing it detects no errors that would inhibit a transition to
RUN mode.
Configure CPUs that are intended to operate independently of a STEP 7 connection to
"Warm restart - RUN" so that the CPU can return to RUN mode on the next power cycle.
S7-1200 Programmable controller
88
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
You can change the current operating mode using the "STOP" or "RUN" commands
(Page 1321) from the online tools of the programming software. You can also include a STP
instruction (Page 310) in your program to change the CPU to STOP mode. This allows you
to stop the execution of your program based on the program logic.
● In STOP mode, the CPU handles any communication requests (as appropriate) and
performs self-diagnostics. The CPU does not execute the user program, and the
automatic updates of the process image do not occur.
● In STARTUP and RUN modes, the CPU performs the tasks shown in the following figure:
STARTUP
A
Clears the I (image) memory area
B
Initializes the Q output (image)
memory area with either zero, the last
value, or the substitute value, as configured, and zeroes PB, PN, and AS-i
outputs
C
Initializes non-retentive M memory and
data blocks to their initial value and
enables configured cyclic interrupt and
time of day events.
Executes the startup OBs.
D
Copies the state of the physical inputs
to I memory
E
Stores any interrupt events into the
queue to be processed after entering
RUN mode
F
Enables the writing of Q memory to the
physical outputs
RUN
①
②
Writes Q memory to the physical outputs
③
Executes the program cycle OBs
④
Performs self-test diagnostics
⑤
Processes interrupts and communications
during any part of the scan cycle
Copies the state of the physical inputs to I
memory
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
89
PLC concepts
5.1 Execution of the user program
STARTUP processing
Whenever the operating mode changes from STOP to RUN, the CPU clears the process
image inputs, initializes the process image outputs and processes the startup OBs. Any read
accesses to the process-image inputs by instructions in the startup OBs read zero rather
than the current physical input value. Therefore, to read the current state of a physical input
during the startup mode, you must perform an immediate read. The startup OBs and any
associated FCs and FBs are executed next. If more than one startup OB exists, each is
executed in order according to the OB number, with the lowest OB number executing first.
Each startup OB includes startup information that helps you determine the validity of
retentive data and the time-of-day clock. You can program instructions inside the startup
OBs to examine these startup values and to take appropriate action. The following startup
locations are supported by the Startup OBs:
Table 5- 1
Startup locations supported by the startup OB
Input
Data Type
Description
LostRetentive
Bool
This bit is true if the retentive data storage areas have been lost
LostRTC
Bool
This bit is true if the time-of-day clock (Real time Clock) has been
lost
The CPU also performs the following tasks during the startup processing:
● Interrupts are queued but not processed during the startup phase
● No cycle time monitoring is performed during the startup phase
● Configuration changes to HSC (high-speed counter), PWM (pulse-width modulation), and
PtP (point-to-point communication) modules can be made in startup
● Actual operation of HSC, PWM and point-to-point communication modules only occurs in
RUN
After the execution of the startup OBs finishes, the CPU goes to RUN mode and processes
the control tasks in a continuous scan cycle.
S7-1200 Programmable controller
90
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.2
Processing the scan cycle in RUN mode
For each scan cycle, the CPU writes the outputs, reads the inputs, executes the user
program, updates communication modules, and responds to user interrupt events and
communication requests. Communication requests are handled periodically throughout the
scan.
These actions (except for user interrupt events) are serviced regularly and in sequential
order. User interrupt events that are enabled are serviced according to priority in the order in
which they occur. For interrupt events, the CPU reads the inputs, executes the OB, and then
writes the outputs, using the associated process image partition (PIP), if applicable.
The system guarantees that the scan cycle will be completed in a time period called the
maximum cycle time; otherwise a time error event is generated.
● Each scan cycle begins by retrieving the current values of the digital and analog outputs
from the process image and then writing them to the physical outputs of the CPU, SB,
and SM modules configured for automatic I/O update (default configuration). When a
physical output is accessed by an instruction, both the output process image and the
physical output itself are updated.
● The scan cycle continues by reading the current values of the digital and analog inputs
from the CPU, SB, and SMs configured for automatic I/O update (default configuration),
and then writing these values to the process image. When a physical input is accessed
by an instruction, the value of the physical input is accessed by the instruction, but the
input process image is not updated.
● After reading the inputs, the user program is executed from the first instruction through
the end instruction. This includes all the program cycle OBs plus all their associated FCs
and FBs. The program cycle OBs are executed in order according to the OB number with
the lowest OB number executing first.
Communications processing occurs periodically throughout the scan, possibly interrupting
user program execution.
Self-diagnostic checks include periodic checks of the system and the I/O module status
checks.
Interrupts can occur during any part of the scan cycle, and are event-driven. When an event
occurs, the CPU interrupts the scan cycle and calls the OB that was configured to process
that event. After the OB finishes processing the event, the CPU resumes execution of the
user program at the point of interruption.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
91
PLC concepts
5.1 Execution of the user program
5.1.3
Organization blocks (OBs)
OBs control the execution of the user program. Specific events in the CPU trigger the
execution of an organization block. OBs cannot call each other or be called from an FC or
FB. Only an event such as a diagnostic interrupt or a time interval can start the execution of
an OB. The CPU handles OBs according to their respective priority classes, with higher
priority OBs executing before lower priority OBs. The lowest priority class is 1 (for the main
program cycle), and the highest priority class is 26.
5.1.3.1
Program cycle OB
Program cycle OBs execute cyclically while the CPU is in RUN mode. The main block of the
program is a program cycle OB. This is where you place the instructions that control your
program and where you call additional user blocks. You can have multiple program cycle
OBs, which the CPU executes in numerical order. Main (OB 1) is the default.
Program cycle events
The program cycle event happens once during each program cycle (or scan). During the
program cycle, the CPU writes the outputs, reads the inputs and executes program cycle
OBs. The program cycle event is required and is always enabled. You might have no
program cycle OBs, or you might have multiple OBs selected for the program cycle event.
After the program cycle event occurs, the CPU executes the lowest numbered program cycle
OB (usually "Main" OB 1). The CPU executes the other program cycle OBs sequentially (in
numerical order) within the program cycle. Program execution is cyclical such that the
program cycle event occurs at the following times:
● When the last startup OB finishes execution
● When the last program cycle OB finishes execution
Table 5- 2
Start information for a program cycle OB
Input
Data type
Description
Initial_Call
Bool
True for initial call of the OB
Remanence
Bool
True if retentive data are available
S7-1200 Programmable controller
92
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.3.2
Startup OB
Startup OBs execute one time when the operating mode of the CPU changes from STOP to
RUN, including powering up in the RUN mode and in commanded STOP-to-RUN transitions.
After completion, the main "Program cycle" begins executing.
Startup events
The startup event happens one time on a STOP to RUN transition and causes the CPU to
execute the startup OBs. You can configure multiple OBs for the startup event. The startup
OBs execute in numerical order.
Table 5- 3
5.1.3.3
Start information for a startup OB
Input
Data type
Description
LostRetentive
Bool
True if retentive data are lost
LostRTC
Bool
True if date and time are lost
Time delay interrupt OB
Time delay interrupt OBs execute after a time delay that you configure.
Time delay interrupt events
You configure time delay interrupt events to occur after a specified delay time has expired.
You assign the delay time with the SRT_DINT instruction. The time delay events interrupt the
program cycle to execute the corresponding time delay interrupt OB. You can attach only
one time delay interrupt OB to a time delay event. The CPU supports four time delay events.
Table 5- 4
Start information for a time delay interrupt OB
Input
Data type
Description
Sign
Word
Identifier passed to triggering call of SRT_DINT
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
93
PLC concepts
5.1 Execution of the user program
5.1.3.4
Cyclic interrupt OB
Cyclic interrupt OBs execute at a specified interval. You can configure up to a total of four
cyclic interrupt events, with one OB corresponding to each cyclic interrupt event.
Cyclic interrupt events
The cyclic interrupt events allow you to configure the execution of an interrupt OB at a
configured cycle time. You configure the initial cycle time when you create the cyclic interrupt
OB. A cyclic event interrupts the program cycle and executes the corresponding cyclic
interrupt OB. Note that the cyclic interrupt event is at a higher priority class than the program
cycle event.
You can attach only one cyclic interrupt OB to a cyclic event.
You can assign a phase shift to each cyclic interrupt so that the execution of cyclic interrupts
can be offset from one another by the phase offset amount. For example, if you have a 5 ms
cyclic event and a 10 ms cyclic event, every ten milliseconds both events occur at the same
moment. If you phase shift the 5 ms event by 1 to 4 ms and the 10 ms event by 0 ms, then
the two events do not occur at the same moment.
The default phase offset is 0. To change the initial phase shift, or to change the cyclic time
for a cyclic event, follow these steps:
1. Right-click the cyclic interrupt OB in the project tree.
2. Select "Properties" from the context menu.
3. Click "Cyclic interrupt" from the "Cyclic interrupt [OB 30]" dialog, and enter the new initial
values.
The maximum phase offset is 6000 ms (6 seconds) or the maximum Cyclic time, whichever
is smaller.
You can also query and change the scan time and the phase shift from your program using
the Query cyclic interrupt (QRY_CINT) and Set cyclic interrupt (SET_CINT) instructions.
Scan time and phase shift values set by the SET_CINT instruction do not persist through a
power cycle or a transition to STOP mode; scan time and phase shift values return to the
initial values following a power cycle or a transition to STOP. The CPU supports a total of
four cyclic interrupt events.
S7-1200 Programmable controller
94
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.3.5
Hardware interrupt OB
Hardware interrupt OBs execute when the relevant hardware event occurs. A hardware
interrupt OB interrupts normal cyclic program execution in reaction to a signal from a
hardware event.
Hardware interrupt events
Changes in the hardware, such as a rising or falling edge on an input point, or an HSC (High
Speed Counter) event trigger hardware interrupt events. The S7-1200 supports one interrupt
OB for each hardware interrupt event. You enable the hardware events in the device
configuration, and assign an OB for an event in the device configuration or with an ATTACH
instruction in the user program. The CPU supports several hardware interrupt events. The
CPU model and the number of input points determine the exact events that are available.
Limits on hardware interrupt events are as follows:
Edges:
● Rising edge events: maximum of 16
● Falling edge events: maximum of 16
HSC events:
● CV=PV: maximum of 6
● Direction changed: maximum of 6
● External reset: maximum of 6
Table 5- 5
Start information for a hardware interrupt OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier of the module that triggered the hardware interrupt
USI
WORD
User structure identifier (16#0001 to 16#FFFF), reserved for future
use
IChannel
USINT
Number of the channel that triggered the interrupt
EventType
BYTE
Identifier for the module-specific event type associated with the
event triggering the interrupt, for example falling edge or rising
edge.
The bits in EventType depend on the triggering module as shown below:
Module / Submodule
Value
Process event
Onboard I/O
from
CPU or SB
16#0
Rising edge
16#1
Falling edge
HSC
16#0
HSC CV=RV1
16#1
HSC direction changed
16#2
HSC reset
16#3
HSC CV=RV2
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
95
PLC concepts
5.1 Execution of the user program
5.1.3.6
Time error interrupt OB
If configured, the time error interrupt OB (OB 80) executes when either the scan cycle
exceeds the maximum cycle time or a time error event occurs. If triggered, it executes,
interrupting normal cyclic program execution or any other event OB.
The occurrence of either of these events generates a diagnostic buffer entry describing the
event. The diagnostic buffer entry is generated regardless of the existence of the time error
interrupt OB.
Time error interrupt events
The occurrence of any of several different time error conditions results in a time error event:
● Scan cycle exceeds maximum cycle time
The "maximum cycle time exceeded" condition results if the program cycle does not
complete within the specified maximum scan cycle time. See the section on "Monitoring
the cycle time in the S7-1200 System Manual" (Page 109) for more information regarding
the maximum cycle time condition, how to configure the maximum scan cycle time in the
properties of the CPU, and how to reset the cycle timer.
● CPU cannot start requested OB because a second time interrupt (cyclic or time-delay)
starts before the CPU finishes execution of the first interrupt OB
● Queue overflow occurred
The "queue overflow occurred" condition results if the interrupts are occurring faster than
the CPU can process them. The CPU limits the number of pending (queued) events by
using a different queue for each event type. If an event occurs when the corresponding
queue is full, the CPU generates a time error event.
All time error events trigger the execution of the time error interrupt OB if it exists. If the time
error interrupt OB does not exist, then the device configuration of the CPU determines the
CPU reaction to the time error:
● The default configuration for time errors, such as starting a second cyclic interrupt before
the CPU has finished the execution of the first, is for the CPU to stay in RUN.
● The default configuration for exceeding the maximum time is for the CPU to change to
STOP.
The user program can extend the program cycle execution time up to ten times the
configured maximum cycle time by executing the RE_TRIGR instruction (Page 309) to
restart the cycle time monitor. However, if two "maximum cycle time exceeded" conditions
occur within the same program cycle without resetting the cycle timer, then the CPU
transitions to STOP, regardless of whether the time error interrupt OB exists. See the section
on "Monitoring the cycle time in the S7-1200 System Manual" (Page 109).
S7-1200 Programmable controller
96
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
Time error interrupt OB includes start information that helps you determine which event and
OB generated the time error. You can program instructions inside the OB to examine these
start values and to take appropriate action.
Table 5- 6
Start information for the time error OB (OB 80)
Input
Data type
Description
fault_id
BYTE
16#01 - maximum cycle time exceeded
16#02 - requested OB cannot be started
16#07 and 16#09 - queue overflow occurred
csg_OBnr
OB_ANY
Number of the OB which was being executed when the error occurred
csg_prio
UINT
Priority of the OB causing the error
To include a time error interrupt OB in your project, you must add a time error interrupt by
double-clicking "Add new block" under "Program blocks" in the tree, then choose
"Organization block", and then "Time error interrupt".
The priority for a new V4.0 CPU is 22. If you exchange a V3.0 CPU for a V4.0 CPU
(Page 1571), the priority is 26, the priority that was in effect for V3.0. In either case, the
priority field is editable and you can set the priority to any value in the range 22 to 26.
5.1.3.7
Diagnostic error interrupt OB
The diagnostic error interrupt OB executes when the CPU detects a diagnostic error, or if a
diagnostics-capable module recognizes an error and you have enabled the diagnostic error
interrupt for the module. The diagnostic error interrupt OB interrupts the normal cyclic
program execution. You can include an STP instruction in the diagnostic error interrupt OB to
put the CPU in STOP mode if you desire your CPU to enter STOP mode upon receiving this
type of error.
If you do not include a diagnostic error interrupt OB in your program, the CPU ignores the
error and stays in RUN mode.
Diagnostic error events
Analog (local), PROFINET, PROFIBUS, and some digital (local) devices are capable of
detecting and reporting diagnostic errors. The occurrence or removal of any of several
different diagnostic error conditions results in a diagnostic error event. The following
diagnostic errors are supported:
● No user power
● High limit exceeded
● Low limit exceeded
● Wire break
● Short circuit
Diagnostic error events trigger the execution of the diagnostic error interrupt OB (OB 82) if it
exists. If it does not exist, then the CPU ignores the error.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
97
PLC concepts
5.1 Execution of the user program
To include a diagnostic error interrupt OB in your project, you must add a diagnostic error
interrupt by double-clicking "Add new block" under "Program blocks" in the tree, then choose
"Organization block", and then "Diagnostic error interrupt".
Note
Diagnostic errors for multi-channel local analog devices (I/O, RTD, and Thermocouple)
The diagnostic error interrupt OB can process only one channel's diagnostic error at a time.
If two channels of a multi-channel device have an error, then the second error only triggers
the diagnostic error interrupt OB under the following conditions: the first channel error clears,
the execution of the diagnostic error interrupt OB that the first error triggered is complete,
and the second error still exists.
The diagnostic error interrupt OB includes startup information that helps you determine
whether the event is due to the occurrence or removal of an error, and the device and
channel which reported the error. You can program instructions inside the diagnostic error
interrupt OB to examine these startup values and to take appropriate action.
Note
Diagnostic error OB Start information references the submodule as a whole if no diagnostic
event is pending
In V3.0, the start information for an outgoing diagnostic error event always indicated the
source of the event. In V4.0, if the outgoing event leaves the submodule with no pending
diagnostics, the start information references the submodule as a whole (16#8000) even if the
source of the event was a specific channel.
For example, if a wire break triggers a diagnostic error event on channel 2, the fault is then
corrected, and the diagnostic error event is cleared, the Start information will not reference
channel 2, but the submodule (16#8000).
S7-1200 Programmable controller
98
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
Table 5- 7
1
Startup information for the diagnostic error interrupt OB
Input
Data type
Description
IOstate
WORD
IO state of the device:
•
Bit 0 = 1 if the configuration is correct, and = 0 if the configuration is no longer correct.
•
Bit 4 = 1 if an error is present (such as a wire break). (Bit 4 = 0 if
there is no error.)
•
Bit 5 = 1 if the configuration is not correct, and = 0 if the configuration is correct again.
•
Bit 7 = 1 if an I/O access error has occurred. Refer to LADDR for
the hardware identifier of the I/O with the access error. (Bit 6 = 0
if there is no error.)
LADDR
HW_ANY
Hardware identifier of the device or functional unit that reported the
error1
Channel
UINT
Channel number
MultiError
BOOL
TRUE if more than one error is present
The LADDR input contains the hardware identifier of the device or functional unit which returned
the error. The hardware identifier is assigned automatically when components are inserted in the
device or network view and appears in the Constants tab of PLC tags. A name is also assigned
automatically for the hardware identifier. These entries in the Constants tab of the PLC tags cannot be changed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
99
PLC concepts
5.1 Execution of the user program
5.1.3.8
Pull or plug of modules OB
The "Pull or plug of modules" OB executes when a configured and non-disabled distributed
I/O module or submodule (PROFIBUS, PROFINET, AS-i) generates an event related to
inserting or removing a module.
Pull or plug of modules event
The following conditions generate a pull of plug of modules event:
● Someone removes or inserts a configured module
● A configured module is not physically present in an expansion rack
● An incompatible module is in an expansion rack that does not correspond to the
configured module
● A compatible module for a configured module is in an expansion rack, but the
configuration does not allow substitutes
● A module or submodule has parameterization errors
If you have not programmed this OB, the CPU remains in RUN mode when any of these
conditions occur with a configured and non-disabled distributed I/O module.
Regardless of whether you have programmed this OB, the CPU changes to STOP mode
when any of these conditions occur with a module in the central rack.
Table 5- 8
Start information for pull or plug of modules OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier
Event_Class
Byte
16#38: module inserted
16#29: module removed
Fault_ID
Byte
Fault identifier
S7-1200 Programmable controller
100
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.3.9
Rack or station failure OB
The "Rack or station failure" OB executes when the CPU detects the failure or
communication loss of a distributed rack or station.
Rack or station failure event
The CPU generates a rack or station failure event when it detects one of the following:
● The failure of a DP master system or of a PROFINET IO system (in the case of either an
incoming or an outgoing event).
● The failure of a DP slave or of an IO device (in the case of either an incoming or an
outgoing event)
● Failure of some of the submodules of a PROFINET I-device
If you have not programmed this OB, the CPU remains in RUN mode when any of these
conditions occur.
Table 5- 9
Start information for rack or station failure OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier
Event_Class
Byte
16#32: Activation of a DP slave or an IO device
16#33: Deactivation of a DP slave or an IO device
16#38: outgoing event
16#39: incoming event
Fault_ID
Byte
Fault identifier
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
101
PLC concepts
5.1 Execution of the user program
5.1.3.10
Time of day OB
Time of day OBs execute based on configured clock time conditions. The CPU supports two
time of day OBs.
Time of day events
You can configure a time of day interrupt event to occur once on a specified date or time or
cyclically with one of the following cycles:
● Every minute: The interrupt occurs every minute.
● Hourly: The interrupt occurs every hour.
● Daily: The interrupt occurs every day at a specified time (hour and minute).
● Weekly: The interrupt occurs every week at a specified time on a specified day of the
week (for example, every Tuesday at 4:30 in the afternoon).
● Monthly: The interrupt occurs every month at a specified time on a specified day of the
month. The day number must be between 1 and 28, inclusive.
● Every end of month: The interrupt occurs on the last day of every month at a specified
time.
● Yearly: The interrupt occurs every year on the specified date (month and day). You
cannot specify a date of February 29.
Table 5- 10
Start information for a time of day event OB
Input
Data type
Description
CaughtUp
Bool
OB call is caught up because time was set forward
SecondTimes Bool
5.1.3.11
OB call is started a second time because time was set backward
Status OB
Status OBs execute if a DPV1 or PNIO slave triggers a status interrupt. This might be the
case if a component (module or rack) of a DPV1 or PNIO slave changes its operating mode,
for example from RUN to STOP.
Status events
For detailed information on events that trigger a status interrupt, refer to the manufacturer's
documentation for the DPV1 or PNIO slave.
Table 5- 11
Start information for status OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier
Slot
UInt
Slot number
Specifier
Word
Alarm specifier
S7-1200 Programmable controller
102
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.3.12
Update OB
Update OBs execute if a DPV1 or PNIO slave triggers an update interrupt.
Update events
For detailed information on events that trigger an update interrupt, refer to the manufacturer's
documentation for the DPV1 or PNIO slave.
Table 5- 12
5.1.3.13
Start information for update OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier
Slot
UInt
Slot number
Specifier
Word
Alarm specifier
Profile OB
Profile OBs execute if a DPV1 or PNIO slave triggers a profile-specific interrupt.
Profile events
For detailed information on events that trigger a profile interrupt, refer to the manufacturer's
documentation for the DPV1 or PNIO slave.
Table 5- 13
5.1.3.14
Start information for profile OB
Input
Data type
Description
LADDR
HW_IO
Hardware identifier
Slot
UInt
Slot number
Specifier
Word
Alarm specifier
MC-Servo and MC-Interpolator OB
STEP 7 creates the read-only MC-Servo and MC-Interpolator OBs automatically when you
create a motion technology object and set the drive interface to be "Analog drive connection"
or "PROFIDrive". You do not need to edit any OB properties or create this OB directly. The
CPU uses these OBs for closed loop control. Refer to the STEP 7 Information System for
further details.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
103
PLC concepts
5.1 Execution of the user program
5.1.3.15
MC-PreServo
You can program the MC-PreServo OB to contain program logic for the STEP 7 program to
execute directly before the MC-Servo OB executes.
MC-PreServo events
The MC-PreServo OB allows you to read out the configured application cycle information in
microseconds.
Table 5- 14
Start information for MC-PreServo OB
Input
Data type
Description
Initial_Call
BOOL
TRUE indicates first call of this OB on transition from STOP to RUN
PIP_Input
BOOL
TRUE indicates the associated process image input is up to date.
PIP_Output
BOOL
TRUE indicates that the CPU transferred the associated process
image output to the outpus in good time after the last cycle.
IO_System
USINT
Number of the distributed I/O system triggering the interrupt
Event_Count
INT
n: number of lost cycles
-1: unknown number of cycles lost (for example, because cycle has
changed)
Synchronous
BOOL
Reserved
CycleTime
UDINT
Display of the application cycle configured for the MC-Servo OB in
microseconds
S7-1200 Programmable controller
104
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.3.16
MC-PostServo
You can program the MC-PreServo OB to contain program logic for the STEP 7 program to
execute directly after the MC-Servo OB executes.
MC-PostServo events
The MC-PreServo OB allows you to read out the configured application cycle information in
microseconds.
Table 5- 15
Start information for MC-PostServo OB
Input
Data type
Description
Initial_Call
BOOL
TRUE indicates first call of this OB on transition from STOP to RUN
PIP_Input
BOOL
TRUE indicates the associated process image input is up to date.
PIP_Output
BOOL
TRUE indicates that the CPU transferred the associated process
image output to the outpus in good time after the last cycle.
IO_System
USINT
Number of the distributed I/O system triggering the interrupt
Event_Count
INT
n: number of lost cycles
-1: unknown number of cycles lost (for example, because cycle has
changed)
5.1.3.17
Synchronous
BOOL
Reserved
CycleTime
UDINT
Display of the application cycle configured for the MC-Servo OB in
microseconds
Event execution priorities and queuing
The CPU processing is controlled by events. An event triggers an interrupt OB to be
executed. You can specify the interrupt OB for an event during the creation of the block,
during the device configuration, or with an ATTACH or DETACH instruction. Some events
happen on a regular basis like the program cycle or cyclic events. Other events happen only
a single time, like the startup event and time delay events. Some events happen when the
hardware triggers an event, such as an edge event on an input point or a high speed counter
event. Events like the diagnostic error and time error event only happen when an error
occurs. The event priorities and queues are used to determine the processing order for the
event interrupt OBs.
The CPU processes events in order of priority where 1 is the lowest priority and 26 is the
highest priority. Prior to V4.0 of the S7-1200 CPU, each type of OB belonged to a fixed
priority class (1 to 26). From V4.0 forward, you can assign a priority class to each OB that
you configure. You configure the priority number in the attributes of the OB properties.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
105
PLC concepts
5.1 Execution of the user program
Interruptible and non-interruptible execution modes
OBs (Page 92) execute in priority order of the events that trigger them. In the Startup
properties of the device configuration of the CPU (Page 170), you can configure OB
execution to be interruptible or non-interruptible. Note that program cycle OBs are always
interruptible, but you can configure all other OBs to be either interruptible or noninterruptible.
If you set interruptible mode, then if an OB is executing and a higher priority event occurs
before the OB completes its execution, the running OB is interrupted to allow the higherpriority event OB to run. The higher-priority event runs, and at its completion, the OB that
was interrupted continues. When multiple events occur while an interruptible OB is
executing, the CPU processes those events in priority order.
If you do not set interruptible mode, then an OB runs to completion when triggered
regardless of any other events that trigger during the time that it is running.
Consider the following two cases where interrupt events trigger a cyclic OB and a time delay
OB. In both cases, the time delay OB (OB201) has no process image partition assignment
(Page 83) and executes at priority 4. The cyclic OB (OB200) has a process image partition
assignment of PIP1 and executes at priority 2. The following illustrations show the difference
in execution between non-interruptible and interruptible execution modes:
Figure 5-1
Case 1: Non-interruptible OB execution
Figure 5-2
Case 2: Interruptible OB execution
Note
If you configure the OB execution mode to be non-interruptible, then a time error OB cannot
interrupt OBs other than program cycle OBs. Prior to V4.0 of the S7-1200 CPU, a time error
OB could interrupt any executing OB. From V4.0 forward, you must configure OB execution
to be interruptible if you want a time error OB (or any other higher priority OB) to be able to
interrupt executing OBs that are not program cycle OBs.
S7-1200 Programmable controller
106
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
Understanding event execution priorities and queuing
The CPU limits the number of pending (queued) events from a single source, using a
different queue for each event type. Upon reaching the limit of pending events for a given
event type, the next event is lost. You can use a time error interrupt OB (Page 96) to
respond to queue overflows.
Note that STEP 7 allows you
to configure some specific
event queueing parameters
for the Cyclic interrupt OB
and the Time of day OB.
For further information on CPU overload behavior and event queueing, refer to the STEP 7
Information System.
Each CPU event has an associated priority. In general, the CPU services events in order of
priority (highest priority first). The CPU services events of the same priority on a "first-come,
first-served" basis.
Table 5- 16
OB events
Event
Quantity allowed
Program cycle
1 program cycle event
Default OB priority
14
Multiple OBs allowed
Startup
1 startup event 1
14
Multiple OBs allowed
Time delay
Up to 4 time events
3
1 OB per event
Cyclic interrupt
Up to 4 events
8
1 OB per event
Hardware interrupt
Up to 50 hardware interrupt events2
18
1 OB per event, but you can use the same OB for
multiple events
18
Time error
1 event (only if configured)3
22 or 264
Diagnostic error
1 event (only if configured)
5
Pull or plug of modules
1 event
6
Rack or station failure
1 event
6
Time of day
Up to 2 events
2
Status
1 event
4
Update
1 event
4
Profile
1 event
4
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
107
PLC concepts
5.1 Execution of the user program
Event
Quantity allowed
MC-Servo
1 event
Default OB priority
25
MC-Interpolator
1 event
24
1
The startup event and the program cycle event never occur at the same time because the startup
event runs to completion before the program cycle event starts.
2
You can have more than 50 hardware interrupt event OBs if you use the DETACH and ATTACH
instructions.
3
You can configure the CPU to stay in RUN if the scan cycle exceeds the maximum scan cycle time
or you can use the RE_TRIGR instruction to reset the cycle time. However, the CPU goes to
STOP mode the second time that one scan cycle exceeds the maximum scan cycle time.
4
The priority for a new V4.0 or V4.1 CPU is 22. If you exchange a V3.0 CPU for a V4.0 or V4.1
CPU, the priority is 26: the priority that was in effect for V3.0. In either case, the priority field is editable and you can set the priority to any value in the range 22 to 26.
Refer to the topic "Exchanging a V3.0 CPU for a V4.1 CPU (Page 1571)" for more details.
In addition, the CPU recognizes other events that do not have associated OBs. The following
table describes these events and the corresponding CPU actions:
Table 5- 17
Additional events
Event
Description
CPU action
I/O access error
Direct I/O read/write error
The CPU logs the first occurrence in the
diagnostic buffer and stays in RUN mode.
You can access the error cause using the
GET_ERROR_ID (Page 311) instruction.
Max cycle time error
CPU exceeds the configured
cycle time twice
The CPU logs the error in the diagnostic
buffer and transitions to STOP mode.
Peripheral access error
I/O error during process image update
The CPU logs the first occurrence in the
diagnostic buffer and stays in RUN mode.
Programming error
program execution error
•
If block-local error handling is enabled,
the system enters an error cause in the
error structure. You can access the error cause using the GET_ERROR_ID
(Page 311) instruction.
•
If global error handling is enabled, the
system enters an access error start
event into the diagnostic buffer and
stays in RUN mode.
Interrupt latency
The interrupt event latency (the time from notification of the CPU that an event has occurred
until the CPU begins execution of the first instruction in the OB that services the event) is
approximately 175 µsec, provided that a program cycle OB is the only event service routine
active at the time of the interrupt event.
S7-1200 Programmable controller
108
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
5.1.4
Monitoring and configuring the cycle time
The cycle time is the time that the CPU operating system requires to execute the cyclic
phase of the RUN mode. The CPU provides two methods of monitoring the cycle time:
● Maximum scan cycle time
● Minimum scan cycle time
Scan cycle monitoring begins after the startup event is complete. Configuration for this
feature appears under the "Device Configuration" for the CPU under "Cycle time".
The CPU always monitors the scan cycle and reacts if the maximum scan cycle time is
exceeded. If the configured maximum scan cycle time is exceeded, an error is generated
and is handled one of two ways:
● If the user program does not include a time error interrupt OB, then the timer error event
generates a diagnostic buffer entry, but the CPU remains in RUN mode. (You can change
the configuration of the CPU to go to STOP mode when it detects a time error, but the
default configuration is to remain in RUN mode.)
● If the user program includes a time error interrupt OB, then the CPU executes it.
The RE_TRIGR instruction (Page 309) (re-trigger cycle time monitoring) allows you to reset
the timer that measures the cycle time. If the elapsed time for the current program cycle
execution is less than ten times the configured maximum scan cycle time, the RE_TRIGR
instruction retriggers the cycle time monitoring and returns with ENO = TRUE. If not, the
RE_TRIGR instruction does not retrigger the cycle time monitoring. It returns ENO = FALSE.
Typically, the scan cycle executes as fast as it can be executed and the next scan cycle
begins as soon as the current one completes. Depending upon the user program and
communication tasks, the time period for a scan cycle can vary from scan to scan. To
eliminate this variation, the CPU supports an optional minimum scan cycle time. If you
enable this optional feature and provide a minimum scan cycle time in ms, then the CPU
delays after the execution of the program cycle OBs until the minimum scan cycle time
elapses before repeating the program cycle.
In the event that the CPU completes the normal scan cycle in less time than the specified
minimum cycle time, the CPU spends the additional time of the scan cycle performing
runtime diagnostics and/or processing communication requests.
In the event that the CPU does not complete the scan cycle in the specified minimum cycle
time, the CPU completes the scan normally (including communication processing) and does
not create any system reaction as a result of exceeding the minimum scan time. The
following table defines the ranges and defaults for the cycle time monitoring functions:
Table 5- 18
Range for the cycle time
Cycle time
Range (ms)
Default
Maximum scan cycle time1
1 to 6000
150 ms
1 to maximum scan cycle time
Disabled
Minimum scan cycle
time2
1
The maximum scan cycle time is always enabled. Configure a cycle time between 1 ms to 6000
ms. The default is 150 ms.
2
The minimum scan cycle time is optional, and is disabled by default. If required, configure a cycle
time between 1 ms and the maximum scan cycle time.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
109
PLC concepts
5.1 Execution of the user program
Configuring the cycle time and communication load
You use the CPU properties in the Device configuration to configure the following
parameters:
● Cycle: You can enter a maximum scan cycle monitoring time. You can also enable and
enter a minimum scan cycle time.
● Communication load: You can configure a percentage of the time to be dedicated for
communication tasks.
For more information about the scan cycle, see "Monitoring the cycle time". (Page 109)
5.1.5
CPU memory
Memory management
The CPU provides the following memory areas to store the user program, data, and
configuration:
● Load memory is non-volatile storage for the user program, data and configuration. When
you download a project to the CPU, the CPU first stores the program in the Load memory
area. This area is located either in a memory card (if present) or in the CPU. The CPU
maintains this non-volatile memory area through a power loss. The memory card
supports a larger storage space than that built-in to the CPU.
● Work memory is volatile storage for some elements of the user project while executing
the user program. The CPU copies some elements of the project from load memory into
work memory. This volatile area is lost when power is removed, and is restored by the
CPU when power is restored.
● Retentive memory is non-volatile storage for a limited quantity of work memory values.
The CPU uses the retentive memory area to store the values of selected user memory
locations during power loss. When a power down or power loss occurs, the CPU restores
these retentive values upon power up.
To display the memory usage for a compiled program block, right-click the block in the
"Program blocks" folder in the STEP 7 project tree and select "Resources" from the context
menu. The Compiliation properties display the load memory and work memory for the
compiled block.
To display the memory usage for the online CPU, double-click "Online and diagnostics" in
STEP 7, expand "Diagnostics", and select "Memory".
S7-1200 Programmable controller
110
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
Retentive memory
You can avoid data loss after power failure by marking certain data as retentive. The CPU
allows you to configure the following data as retentive:
● Bit memory (M): You can define the size of retentive memory for bit memory in the PLC
tag table or in the assignment list. Retentive bit memory always starts at MB0 and runs
consecutively up through a specified number of bytes. Specify this value from the PLC
tag table or in the assignment list by clicking the "Retain" toolbar icon. Enter the number
of M bytes to retain starting at MB0.
Note: For any block, you can display the assignment list by selecting a block in the
Program Blocks folder and then selecting he Tools > Assignment list menu command.
● Tags of a function block (FB): If an FB is of type "Optimized block access", then the
interface editor for this FB includes a "Retain" column. In this column, you can select
either "Retain", "Non-retain", or "Set in IDB" individually for each tag. When you place
such an FB in the program, the instance DB that corresponds to the FB includes this
"Retain" column as well. You can only change the retentive state of a tag from within the
instance DB interface editor if you selected "Set in IDB" (Set in instance data block) in the
Retain selection for the tag in the optimized FB.
If an FB is not of type "Optimized block access", then the interface editor for this FB does
not include a "Retain" column. When you place such an FB in the program, the instance
DB that corresponds to the FB does, however, include a "Retain" column that is available
for edit. In this case, selecting the "Retain" option for any tag results in the selection of all
tags. Similarly, deselecting the option for any tag results in the deselection of all tags.
To view or modify whether an FB is optimized, open the properties of the FB and select
the attributes.
● Tags of a global data block: The behavior of a global DB with regard to retentive state
assignment is similar to that of an FB. Depending on the block access setting you can
define the retentive state either for individual tags or for all tags of a global data block.
– If you select "Optimized" when you create the DB, you can set the retentive state for
each individual tag.
– If you select "Standard - compatible with S7-300/400" when you create the DB, the
retentive-state setting applies to all tags of the DB; either all tags are retentive or no
tag is retentive.
The CPU supports a total of 10240 bytes of retentive data. To see how much is available,
from the PLC tag table or the assignment list, click the "Retain" toolbar icon. Although this is
where the retentive range is specified for M memory, the second row indicates the total
remaining memory available for M and DB combined. Note that for this value to be accurate,
you must compile all data blocks with retentive tags.
Note
Downloading a program does not clear or make any changes to existing values in retentive
memory. If you want to clear retentive memory before a download, then reset your CPU to
factory settings prior to downloading the program.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
111
PLC concepts
5.1 Execution of the user program
5.1.5.1
System and clock memory
You use the CPU properties to enable bytes for "system memory" and "clock memory". Your
program logic can reference the individual bits of these functions by their tag names.
● You can assign one byte in M memory for system memory. The byte of system memory
provides the following four bits that can be referenced by your user program by the
following tag names:
– First cycle: (Tag name "FirstScan") bit is set to1 for the duration of the first scan after
the startup OB finishes. (After the execution of the first scan, the "first scan" bit is set
to 0.)
– Diagnostics status changed: (Tag name: "DiagStatusUpdate") is set to 1 for one scan
after the CPU logs a diagnostic event. Because the CPU does not set the
"DiagStatusUpdate" bit until the end of the first execution of the program cycle OBs,
your user program cannot detect if there has been a diagnostic change either during
the execution of the startup OBs or the first execution of the program cycle OBs.
– Always 1 (high): (Tag name "AlwaysTRUE") bit is always set to 1.
– Always 0 (low): (Tag name "AlwaysFALSE") bit is always set to 0.
● You can assign one byte in M memory for clock memory. Each bit of the byte configured
as clock memory generates a square wave pulse. The byte of clock memory provides 8
different frequencies, from 0.5 Hz (slow) to 10 Hz (fast). You can use these bits as control
bits, especially when combined with edge instructions, to trigger actions in the user
program on a cyclic basis.
The CPU initializes these bytes on the transition from STOP mode to STARTUP mode. The
bits of the clock memory change synchronously to the CPU clock throughout the STARTUP
and RUN modes.
CAUTION
Risks with overwriting the system memory or clock memory bits
Overwriting the system memory or clock memory bits can corrupt the data in these
functions and cause your user program to operate incorrectly, which can cause damage to
equipment and injury to personnel.
Because both the clock memory and system memory are unreserved in M memory,
instructions or communications can write to these locations and corrupt the data.
Avoid writing data to these locations to ensure the proper operation of these functions, and
always implement an emergency stop circuit for your process or machine.
S7-1200 Programmable controller
112
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
System memory configures a byte with bits that turn on (value = 1) for a specific event.
Table 5- 19
7
6
System memory
3
2
1
0
Reserved
5
4
Always off
Always on
First scan indicator
Value 0
Value 0
Value 1
Diagnostic status indicator
•
1: Change
•
0: No change
•
1: First scan after
startup
•
0: Not first scan
Clock memory configures a byte that cycles the individual bits on and off at fixed intervals.
Each clock bit generates a square wave pulse on the corresponding M memory bit. These
bits can be used as control bits, especially when combined with edge instructions, to trigger
actions in the user code on a cyclic basis.
Table 5- 20
Clock memory
Bit number
7
6
5
4
3
2
1
0
Period (s)
2.0
1.6
1.0
0.8
0.5
0.4
0.2
0.1
Frequency (Hz)
0.5
0.625
1
1.25
2
2.5
5
10
Tag name
Because clock memory runs asynchronously to the CPU cycle, the status of the clock memory can
change several times during a long cycle.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
113
PLC concepts
5.1 Execution of the user program
5.1.6
Diagnostics buffer
The CPU supports a diagnostics buffer that contains an entry for each diagnostic event.
Each entry includes a date and time the event occurred, an event category, and an event
description. The entries are displayed in chronological order with the most recent event at
the top. Up to 50 most recent events are available in this log. When the log is full, a new
event replaces the oldest event in the log. When power is lost, the events are saved.
The following types of events are recorded in the diagnostics buffer:
● Each system diagnostic event; for example, CPU errors and module errors
● Each state change of the CPU (each power up, each transition to STOP, each transition
to RUN)
To access the diagnostics buffer (Page 1322), you must be online. From the "Online &
diagnostics" view, locate the diagnostics buffer under "Diagnostics > Diagnostics buffer".
Reducing the number of security diagnostic events
Some security events generate repeated entries in the diagnostics buffer. These messages
can fill up the diagnostics buffer and potentially obscure other event messages. You can
configure the PLC to limit the number of diagnostic messages from security events. You
make selections in the device configuration of the CPU based on the time interval in which
you want to suppress recurring messages:
If you choose to summarize security events within a time interval, you have the choice of
setting a time interval in seconds, minutes, or hours, and a numerical value in the range 1 ..
255.
If you choose to restrict security events, you will be restricting these types of events:
● Going online with the correct or incorrect password
● Manipulated communications data detected
● Manipulated data detected on memory card
● Manipulated firmware update file detected
● Changed protection level (access protection) downloaded to the CPU
● Password legitimization restricted or enabled (by instruction or CPU display)
● Online access denied due to the possible number of simultaneous access attempts being
exceeded
● Timeout when an existing online connection is inactive
● Logging in to the Web server with the correct or incorrect password
S7-1200 Programmable controller
114
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.1 Execution of the user program
● Creating a backup of the CPU
● Restoring the CPU configuration
5.1.7
Time of day clock
The CPU supports a time-of-day clock. A super-capacitor supplies the energy required to
keep the clock running during times when the CPU is powered down. The super-capacitor
charges while the CPU has power. After the CPU has been powered up at least 24 hours,
then the super-capacitor has sufficient charge to keep the clock running for typically 20 days.
STEP 7 sets the time-of-day clock to system time, which has a default value out of the box or
following a factory reset. To utilize the time-of-day clock, you must set it. Timestamps such
as those for diagnostic buffer entries, data log files, and data log entries are based on the
system time. You set the time of day from the "Set time of day" function (Page 1316) in the
"Online & diagnostics" view of the online CPU. STEP 7 then calculates the system time from
the time you set plus or minus the Windows operating system offset from UTC (Coordinated
Universal Time). Setting the time of day to the current local time produces a system time of
UTC if your Windows operating system settings for time zone and daylight savings time
correspond to your locale.
STEP 7 includes instructions (Page 338) to read and write the system time (RD_SYS_T and
WR_SYS_T), to read the local time (RD_LOC_T), and to set the time zone
(SET_TIMEZONE). The RD_LOC_T instruction calculates local time using the time zone and
daylight saving time offsets that you set in the "Time of day" configuration in the general
properties of the CPU (Page 170). These settings enable you to set your time zone for local
time, optionally enable daylight saving time, and specify the start and end dates and times
for daylight saving time. You can also use the SET_TIMEZONE instructions to configure
these settings.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
115
PLC concepts
5.1 Execution of the user program
5.1.8
Configuring the outputs on a RUN-to-STOP transition
You can configure the behavior of the digital and analog outputs when the CPU is in STOP
mode. For any output of a CPU, SB or SM, you can set the outputs to either freeze the value
or use a substitute value:
● Substituting a specified output value (default): You enter a substitute value for each
output (channel) of that CPU, SB, or SM device.
The default substitute value for digital output channels is OFF, and the default substitute
value for analog output channels is 0.
● Freezing the outputs to remain in last state: The outputs retain their current value at the
time of the transition from RUN to STOP. After power up, the outputs are set to the
default substitute value.
You configure the behavior of the outputs in Device Configuration. Select the individual
devices and use the "Properties" tab to configure the outputs for each device.
Note
Some distibuted I/O modules offer additional settings for the reaction to CPU stop mode.
Select from the list of choices in Device Configuration for those modules.
When the CPU changes from RUN to STOP, the CPU retains the process image and writes
the appropriate values for both the digital and analog outputs, based upon the configuration.
S7-1200 Programmable controller
116
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
5.2
Data storage, memory areas, I/O and addressing
5.2.1
Accessing the data of the S7-1200
STEP 7 facilitates symbolic programming. You create symbolic names or "tags" for the
addresses of the data, whether as PLC tags relating to memory addresses and I/O points or
as local variables used within a code block. To use these tags in your user program, simply
enter the tag name for the instruction parameter.
For a better understanding of how the CPU structures and addresses the memory areas, the
following paragraphs explain the "absolute" addressing that is referenced by the PLC tags.
The CPU provides several options for storing data during the execution of the user program:
● Global memory: The CPU provides a variety of specialized memory areas, including
inputs (I), outputs (Q) and bit memory (M). This memory is accessible by all code blocks
without restriction.
● PLC tag table: You can enter symbolic names in the STEP 7 PLC tag table for specific
memory locations. These tags are global to the STEP 7 program and allow programming
with names that are meaningful for your application.
● Data block (DB): You can include DBs in your user program to store data for the code
blocks. The data stored persists when the execution of the associated code block comes
to an end. A "global" DB stores data that can be used by all code blocks, while an
instance DB stores data for a specific FB and is structured by the parameters for the FB.
● Temp memory: Whenever a code block is called, the operating system of the CPU
allocates the temporary, or local, memory (L) to be used during the execution of the
block. When the execution of the code block finishes, the CPU reallocates the local
memory for the execution of other code blocks.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
117
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
Each different memory location has a unique address. Your user program uses these
addresses to access the information in the memory location. References to the input (I) or
output (Q) memory areas, such as I0.3 or Q1.7, access the process image. To immediately
access the physical input or output, append the reference with ":P" (such as I0.3:P, Q1.7:P,
or "Stop:P").
Table 5- 21
1
Memory areas
Memory area
Description
Force
Retentive
I
Process image input
Copied from physical inputs at the beginning of
the scan cycle
No
No
I_:P 1
(Physical input)
Immediate read of the physical input points on
the CPU, SB, and SM
Yes
No
Q
Process image output
Copied to physical outputs at the beginning of
the scan cycle
No
No
Q_:P 1
(Physical output)
Immediate write to the physical output points
on the CPU, SB, and SM
Yes
No
M
Bit memory
Control and data memory
No
Yes
(optional)
L
Temp memory
Temporary data for a block local to that block
No
No
DB
Data block
Data memory and also parameter memory for
FBs
No
Yes
(optional)
To immediately access (read or write) the physical inputs and physical outputs, append a ":P" to
the address or tag (such as I0.3:P, Q1.7:P, or "Stop:P").
Each different memory location has a unique address. Your user program uses these
addresses to access the information in the memory location. The absolute address consists
of the following elements:
● Memory area identifier (such as I, Q, or M)
● Size of the data to be accessed ("B' for Byte, "W" for Word, or "D" for DWord)
● Starting address of the data (such as byte 3 or word 3)
S7-1200 Programmable controller
118
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
When accessing a bit in the address for a Boolean value, you do not enter a mnemonic for
the size. You enter only the memory area, the byte location, and the bit location for the data
(such as I0.0, Q0.1, or M3.4).
A
Memory area identifier
E
Bytes of the memory area
B
Byte address: byte 3
F
Bits of the selected byte
C
Separator ("byte.bit")
D
Bit location of the byte (bit 4 of 8)
In the example, the memory area and byte address (M = bit memory area, and 3 = Byte 3)
are followed by a period (".") to separate the bit address (bit 4).
Accessing the data in the memory areas of the CPU
STEP 7 facilitates symbolic programming. Typically, you create tags either in the PLC tag
table, a data block, or in the interface of an OB, FC, or FB. These tags include a name, data
type, offset, and comment. Additionally, in a data block, you can specify a start value. You
can use these tags when programming by entering the tag name at the instruction
parameter. Optionally you can enter the absolute operand (memory area, size and offset) at
the instruction parameter. The examples in the following sections show how to enter
absolute operands. The % character is inserted automatically in front of the absolute
operand by the program editor. You can toggle the view in the program editor to one of
these: symbolic, symbolic and absolute, or absolute.
I (process image input): The CPU samples the peripheral (physical) input points just prior to
the cyclic OB execution of each scan cycle and writes these values to the input process
image. You can access the input process image as bits, bytes, words, or double words. Both
read and write access is permitted, but typically, process image inputs are only read.
Table 5- 22
Absolute addressing for I memory
Bit
I[byte address].[bit address]
I0.1
Byte, Word, or Double Word
I[size][starting byte address]
IB4, IW5, or ID12
By appending a ":P" to the address, you can immediately read the digital and analog inputs
of the CPU, SB, SM or distributed module. The difference between an access using I_:P
instead of I is that the data comes directly from the points being accessed rather than from
the input process image. This I_:P access is referred to as an "immediate read" access
because the data is retrieved immediately from the source instead of from a copy that was
made the last time the input process image was updated.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
119
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
Because the physical input points receive their values directly from the field devices
connected to these points, writing to these points is prohibited. That is, I_:P accesses are
read-only, as opposed to I accesses which can be read or write.
I_:P accesses are also restricted to the size of inputs supported by a single CPU, SB, or SM,
rounded up to the nearest byte. For example, if the inputs of a 2 DI / 2 DQ SB are configured
to start at I4.0, then the input points can be accessed as I4.0:P and I4.1:P or as IB4:P.
Accesses to I4.2:P through I4.7:P are not rejected, but make no sense since these points are
not used. Accesses to IW4:P and ID4:P are prohibited since they exceed the byte offset
associated with the SB.
Accesses using I_:P do not affect the corresponding value stored in the input process image.
Table 5- 23
Absolute addressing for I memory (immediate)
Bit
I[byte address].[bit address]:P
I0.1:P
Byte, Word, or Double word
I[size][starting byte address]:P
IB4:P, IW5:P, or ID12:P
Q (process image output): The CPU copies the values stored in the output process image to
the physical output points. You can access the output process image in bits, bytes, words, or
double words. Both read and write access is permitted for process image outputs.
Table 5- 24
Absolute addressing for Q memory
Bit
Q[byte address].[bit address]
Q1.1
Byte, Word, or Double word
Q[size][starting byte address]
QB5, QW10, QD40
By appending a ":P" to the address, you can immediately write to the physical digital and
analog outputs of the CPU, SB, SM or distributed module. The difference between an access
using Q_:P instead of Q is that the data goes directly to the points being accessed in addition
to the output process image (writes to both places). This Q_:P access is sometimes referred
to as an "immediate write" access because the data is sent immediately to the target point;
the target point does not have to wait for the next update from the output process image.
Because the physical output points directly control field devices that are connected to these
points, reading from these points is prohibited. That is, Q_:P accesses are write-only, as
opposed to Q accesses which can be read or write.
Q_:P accesses are also restricted to the size of outputs supported by a single CPU, SB, or
SM, rounded up to the nearest byte. For example, if the outputs of a 2 DI / 2 DQ SB are
configured to start at Q4.0, then the output points can be accessed as Q4.0:P and Q4.1:P or
as QB4:P. Accesses to Q4.2:P through Q4.7:P are not rejected, but make no sense since
these points are not used. Accesses to QW4:P and QD4:P are prohibited since they exceed
the byte offset associated with the SB.
Accesses using Q_:P affect both the physical output as well as the corresponding value
stored in the output process image.
Table 5- 25
Absolute addressing for Q memory (immediate)
Bit
Q[byte address].[bit address]:P
Q1.1:P
Byte, Word, or Double word
Q[size][starting byte address]:P
QB5:P, QW10:P or QD40:P
S7-1200 Programmable controller
120
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
M (bit memory area): Use the bit memory area (M memory) for both control relays and data
to store the intermediate status of an operation or other control information. You can access
the bit memory area in bits, bytes, words, or double words. Both read and write access is
permitted for M memory.
Table 5- 26
Absolute addressing for M memory
Bit
M[byte address].[bit address]
M26.7
Byte, Word, or Double Word
M[size][starting byte address]
MB20, MW30, MD50
Temp (temporary memory): The CPU allocates the temp memory on an as-needed basis.
The CPU allocates the temp memory for the code block and initializes the memory locations
to 0 at the time when it starts the code block (for an OB) or calls the code block (for an FC or
FB).
Temp memory is similar to M memory with one major exception: M memory has a "global"
scope, and temp memory has a "local" scope:
● M memory: Any OB, FC, or FB can access the data in M memory, meaning that the data
is available globally for all of the elements of the user program.
● Temp memory: The CPU restricts access to the data in temp memory to the OB, FC, or
FB that created or declared the temp memory location. Temp memory locations remain
local and different code blocks do not share temp memory, even when the code block
calls another code block. For example: When an OB calls an FC, the FC cannot access
the temp memory of the OB that called it.
The CPU provides temp (local) memory for each OB priority level:
● 16 Kbytes for startup and program cycle, including associated FBs and FCs
● 6 Kbytes for each additional interrupt event thread, including associated FBs and FCs
You access temp memory by symbolic addressing only.
You can find out the amount of temp (local) memory that the blocks in your program use
through the call structure in STEP 7. From the project tree select Program info and then
select the Call structure tab. You will see all of the OBs in your program and you can drill
down to see the blocks that they call. For each block, you can see the local data allocation.
You can also access the Call structure display from the STEP 7 Tools > Call structure menu
command.
DB (data block): Use the DB memory for storing various types of data, including intermediate
status of an operation or other control information parameters for FBs, and data structures
required for many instructions such as timers and counters. You can access data block
memory in bits, bytes, words, or double words. Both read and write access is permitted for
read/write data blocks. Only read access is permitted for read-only data blocks.
Table 5- 27
Absolute addressing for DB memory
Bit
DB[data block number].DBX[byte address].[bit address]
DB1.DBX2.3
Byte, Word, or Double
Word
DB[data block number].DB [size][starting
byte address]
DB1.DBB4, DB10.DBW2,
DB20.DBD8
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
121
PLC concepts
5.2 Data storage, memory areas, I/O and addressing
Note
When you specify an absolute address in LAD or FBD, STEP 7 precedes this address with a
"%" character to indicate that it is an absolute address. While programming, you can enter
an absolute address either with or without the "%" character (for example %I0.0 or I.0). If
omitted, STEP 7 supplies the "%" character.
In SCL, you must enter the "%" before the address to indicate that it is an absolute address.
Without the "%", STEP 7 generates an undefined tag error at compile time
Configuring the I/O in the CPU and I/O modules
When you add a CPU and I/O modules to your
device configuration, STEP 7 automatically assigns
I and Q addresses. You can change the default
addressing by selecting the address field in the
device configuration and entering new numbers.
• STEP 7 assigns digital inputs and outputs in
groups of 8 points (1 byte), whether the module
uses all the points or not.
• STEP 7 allocates analog inputs and outputs in
groups of 2, where each analog poing occupies
2 bytes (16 bits).
The figure shows an example of a CPU 1214C with two SMs and one SB. In this example,
you could change the address of the DI8 module to 2 instead of 8. The tool assists you by
changing address ranges that are the wrong size or conflict with other addresses.
S7-1200 Programmable controller
122
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.3 Processing of analog values
5.3
Processing of analog values
Analog signal modules provide input signals or expect output values that represent either a
voltage range or a current range. These ranges are ±10 V, ±5 V, ±2.5 V, or 0 - 20 mA. The
values returned by the modules are integer values where 0 to 27648 represents the rated
range for current, and -27648 to 27648 for voltage. Anything outside the range represents
either an overflow or underflow. See the tables for analog input representation (Page 1471)
and analog output representation (Page 1472) for details about the types of out-of-range
values.
In your control program, you probably need to use these values in engineering units, for
example to represent a volume, temperature, weight or other quantitative value. To do this
for an analog input, you must first normalize the analog value to a real (floating point) value
from 0.0 to 1.0. Then you must scale it to the minimum and maximum values of the
engineering units that it represents. For values that are in engineering units that you need to
convert to an analog output value, you first normalize the value in engineering units to a
value between 0.0 and 1.0, and then scale it between 0 and 27648 or -27648 to 27648,
depending on the range of the analog module. STEP 7 provides the NORM_X and SCALE_X
instructions (Page 296) for this purpose. You can also use the CALCULATE instruction
(Page 255) to scale the analog values (Page 42).
Example: analog value processing
Consider, for example, an analog input that has a current range of 0 - 20 mA. The analog
input module returns values in the range 0 to 24768 for measured values. For this example,
consider that you are using this analog input value to measure a temperature range from
50 °C to 100 °C. A few sample values would have the following meanings:
Analog input value
Engineering units
0
50 °C
6192
62.5 °C
12384
75 °C
18576
87.5 °C
24768
100 °C
The calculation for determining engineering units from the analog input value in this example
is as follows:
Engineering units value = 50 + (Analog input value) * (100 - 50) / (24768 - 0)
For the general case, the equation would be:
Englineering units value = (Low range of engineering units) +
(Analog input value) *
(High range of engineering units - Low range of engineering units) /
(Maximum analog input range - Minimum analog input range)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
123
PLC concepts
5.3 Processing of analog values
In PLC applications, the typical method is to normalize the analog input value to a floating
point value between 0.0 and 1.0. Then, you would scale the resulting value to a floating point
value in the range of your engineering units. For simplicity, the following LAD instructions
use constant values for the ranges; you might actually choose to use tags:
Network 1
Network 2
S7-1200 Programmable controller
124
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
5.4
Data types
Data types are used to specify both the size of a data element as well as how the data are to
be interpreted. Each instruction parameter supports at least one data type, and some
parameters support multiple data types. Hold the cursor over the parameter field of an
instruction to see which data types are supported for a given parameter.
A formal parameter is the identifier on an instruction that marks the location of data to be
used by that instruction (example: the IN1 input of an ADD instruction). An actual parameter
is the memory location (preceded by a "%" character) or constant containing the data to be
used by the instruction (example %MD400 "Number_of_Widgets"). The data type of the
actual parameter specified by you must match one of the supported data types of the formal
parameter specified by the instruction.
When specifying an actual parameter, you must specify either a tag (symbol) or an absolute
(direct) memory address. Tags associate a symbolic name (tag name) with a data type,
memory area, memory offset, and comment, and can be created either in the PLC tags
editor or in the Interface editor for a block (OB, FC, FB and DB). If you enter an absolute
address that has no associated tag, you must use an appropriate size that matches a
supported data type, and a default tag will be created upon entry.
All data types except String, Struct, Array, and DTL are available in the PLC tags editor and
the block Interface editors. String, Struct, Array, and DTL are available only in the block
Interface editors. You can also enter a constant value for many of the input parameters.
● Bit and Bit sequences (Page 126): Bool (Boolean or bit value), Byte (8-bit byte value),
Word (16-bit value), DWord (32-bit double word value)
● Integer (Page 127)
– USInt (unsigned 8-bit integer), SInt (signed 8-bit integer),
– UInt (unsigned 16-bit integer), Int (signed 16-bit integer)
– UDInt (unsigned 32-bit integer), DInt (signed 32-bit integer)
● Floating-point Real (Page 127): Real (32-bit Real or floating-point value), LReal (64-bit
Real or floating-point value)
● Time and Date (Page 128): Time (32-bit IEC time value), Date (16-bit date value), TOD
(32-bit time-of-day value), DTL (12-byte date-and-time structure)
● Character and String (Page 130): Char (8-bit single character), String (variable-length
string of up to 254 characters)
● Array (Page 132)
● Data structure (Page 133): Struct
● PLC data type (Page 133)
● Variant data type (Page 134)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
125
PLC concepts
5.4 Data types
Although not available as data types, the following BCD numeric format is supported by the
conversion instructions:
Table 5- 28
5.4.1
Size and range of the BCD format
Format
Size (bits)
Numeric Range
Constant Entry Examples
BCD16
16
-999 to 999
123, -123
BCD32
32
-9999999 to 9999999
1234567, -1234567
Bool, Byte, Word, and DWord data types
Table 5- 29
Bit and bit sequence data types
Data
type
Bit
size
Number
type
Number
range
Constant
examples
Address
examples
Bool
1
Boolean
FALSE or TRUE
TRUE
I1.0
Q0.1
M50.7
DB1.DBX2.3
Tag_name
Byte
Word
8
16
Binary
2#0 or 2#1
2#0
Unsigned integer
0 or 1
1
Octal
8#0 or 8#1
8#1
Hexadecimal
16#0 or 16#1
16#1
Binary
2#0 to 2#1111_1111
2#1000_1001
Unsigned integer
0 to 255
15
Signed integer
-128 to 127
-63
Octal
8#0 to 8#377
8#17
Hexadecimal
B#16#0 to B#16#FF, 16#0 to
16#FF
B#16#F, 16#F
Binary
Signed integer
2#0 to 2#1111_1111_1111_1111 2#1101_0010_1001_0110 MW10
DB1.DBW2
0 to 65535
61680
Tag_name
-32768 to 32767
72
Octal
8#0 to 8#177_777
8#170_362
Hexadecimal
W#16#0 to W#16#FFFF,
W#16#F1C0, 16#A67B
Unsigned integer
IB2
MB10
DB1.DBB4
Tag_name
16#0 to 16#FFFF
DWord
32
Binary
2#0 to
2#1111_1111_1111_1111_1111
_1111_1111_1111
2#1101_0100_1111_1110 MD10
_1000_1100
DB1.DBD8
Tag_name
Unsigned integer*
0 to 4_294_967_295
15_793_935
Signed integer*
-2_147_483_648 to
2_147_483_647
-400000
Octal
8#0 to 8#37_777_777_777
8#74_177_417
Hexadecimal
DW#16#0000_0000 to
DW#16#FFFF_FFFF,
DW#16#20_F30A,
16#B_01F6
16#0000_0000 to
16#FFFF_FFFF
* The underscore "_" is a thousands separator to enhance readability for numbers greater than eight digits.
S7-1200 Programmable controller
126
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
5.4.2
Integer data types
Table 5- 30
Data
type
5.4.3
Integer data types (U = unsigned, S = short, D= double)
Bit size Number Range
Constant examples
Address
examples
USInt
8
0 to 255
78, 2#01001110
SInt
8
-128 to 127
+50, 16#50
UInt
16
0 to 65,535
65295, 0
Int
16
-32,768 to 32,767
30000, +30000
UDInt
32
0 to 4,294,967,295
4042322160
DInt
32
-2,147,483,648 to 2,147,483,647
-2131754992
MB0, DB1.DBB4,
Tag_name
MW2, DB1.DBW2,
Tag_name
MD6, DB1.DBD8,
Tag_name
Floating-point real data types
Real (or floating-point) numbers are represented as 32-bit single-precision numbers (Real),
or 64-bit double-precision numbers (LReal) as described in the ANSI/IEEE 754-1985
standard. Single-precision floating-point numbers are accurate up to 6 significant digits and
double-precision floating point numbers are accurate up to 15 significant digits. You can
specify a maximum of 6 significant digits (Real) or 15 (LReal) when entering a floating-point
constant to maintain precision.
Table 5- 31
Floating-point real data types (L=Long)
Data
type
Bit size Number range
Constant Examples
Real
32
-3.402823e+38 to -1.175 495e-38, 123.456, -3.4, 1.0e-5
±0,
+1.175 495e-38 to
+3.402823e+38
MD100,
DB1.DBD8,
Tag_name
LReal
64
-1.7976931348623158e+308 to
-2.2250738585072014e-308,
±0,
+2.2250738585072014e-308 to
+1.7976931348623158e+308
DB_name.var_nam
e
12345.123456789e40,
1.2E+40
Address examples
Rules:
•
No direct addressing support
•
Can be assigned in an
OB, FB, or FC
block interface
table
Calculations that involve a long series of values including very large and very small numbers
can produce inaccurate results. This can occur if the numbers differ by 10 to the power of x,
where x > 6 (Real), or 15 (LReal). For example (Real): 100 000 000 + 1 = 100 000 000.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
127
PLC concepts
5.4 Data types
5.4.4
Time and Date data types
Table 5- 32
Time and date data types
Data type
Size
Range
Constant Entry Examples
Time
32 bits
T#-24d_20h_31m_23s_648ms to
T#24d_20h_31m_23s_647ms
T#5m_30s
T#1d_2h_15m_30s_45ms
TIME#10d20h30m20s630ms
500h10000ms
10d20h30m20s630ms
Stored as: -2,147,483,648 ms to
+2,147,483,647 ms
Date
16 bits
D#1990-1-1 to D#2168-12-31
D#2009-12-31
DATE#2009-12-31
2009-12-31
Time_of_Day 32 bits
TOD#0:0:0.0 to TOD#23:59:59.999
TOD#10:20:30.400
TIME_OF_DAY#10:20:30.400
23:10:1
DTL
(Date and
Time Long)
Min.: DTL#1970-01-01-00:00:00.0
Max.: DTL#2262-04-11:23:47:16.854 775
807
DTL#2008-12-1620:30:20.250
12
bytes
Time
TIME data is stored as a signed double integer interpreted as milliseconds. The editor format
can use information for day (d), hours (h), minutes (m), seconds (s) and milliseconds (ms).
It is not necessary to specify all units of time. For example T#5h10s and 500h are valid.
The combined value of all specified unit values cannot exceed the upper or lower limits in
milliseconds for the Time data type (-2,147,483,648 ms to +2,147,483,647 ms).
Date
DATE data is stored as an unsigned integer value which is interpreted as the number of days
added to the base date 01/01/1990, to obtain the specified date. The editor format must
specify a year, month and day.
TOD
TOD (TIME_OF_DAY) data is stored as an unsigned double integer which is interpreted as
the number of milliseconds since midnight for the specified time of day (Midnight = 0 ms).
The hour (24hr/day), minute, and second must be specified. The fractional second
specification is optional.
S7-1200 Programmable controller
128
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
DTL
DTL (Date and Time Long) data type uses a12 byte structure that saves information on date
and time. You can define DTL data in either the Temp memory of a block or in a DB. A value
for all components must be entered in the "Start value" column of the DB editor.
Table 5- 33
Size and range for DTL
Length
(bytes)
Format
Value range
Example of value
input
12
Clock and calendar
Min.: DTL#1970-01-01-00:00:00.0
DTL#2008-12-1620:30:20.250
Year-MonthMax.: DTL#2554-12-31-23:59:59.999 999
Day:Hour:Minute:
999
Second.Nanoseconds
Each component of the DTL contains a different data type and range of values. The data
type of a specified value must match the data type of the corresponding components.
Table 5- 34
Elements of the DTL structure
Byte
Component
Data type
Value range
0
Year
UINT
1970 to 2554
2
Month
USINT
1 to 12
3
Day
USINT
1 to 31
4
Weekday 1
USINT
1(Sunday) to 7(Saturday) 1
5
Hour
USINT
0 to 23
6
Minute
USINT
0 to 59
7
Second
USINT
0 to 59
8
Nanoseconds
UDINT
0 to 999 999 999
1
9
10
11
1
The format Year-Month-Day:Hour:Minute:
Second.Nanosecond does not include the weekday.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
129
PLC concepts
5.4 Data types
5.4.5
Character and String data types
Table 5- 35
Character and String data types
Data type
Size
Range
Constant Entry Examples
Char
8 bits
16#00 to 16#FF
'A', 't', '@', 'ä', '∑'
WChar
16 bits
16#0000 to 16#FFFF
'A', 't', '@', 'ä', '∑', Asian characters, Cyrillic
characters, and others
String
n+ 2 bytes
n = (0 to 254 bytes)
"ABC"
WString
n+ 2 words
n = (0 to 65534 words)
"ä123@XYZ.COM"
Char and WChar
A Char occupies one byte in memory and stores a single character coded in ASCII format,
including the extended ASCII character codes. A WChar occupies one word in memory and
can contain any double-byte character representation.
The editor syntax uses a single quote character before and after the character. You can use
visible characters and control characters.
String and WString
The CPU supports the String data type for storing a sequence of single-byte characters. The
String data type contains a total character count (number of characters in the string) and the
current character count. The String type provides up to 256 bytes for storing the maximum
total character count (1 byte), the current character count (1 byte), and up to 254 bytes in the
string. Each byte in a String data type can be any value from 16#00 - 16#FF.
The WString data type provides for longer strings of one-word (double-byte) values. The first
word contains the maximum total character count; the next word contains the total character
count, and the following string can contain up to 65534 words. Each word in a WString data
type can be any value from 16#0000 - 16#FFFF.
You can use literal strings (constants) for instruction parameters of type IN using single
quotes. For example, ‘ABC’ is a three-character string that could be used as input for
parameter IN of the S_CONV instruction. You can also create string variables by selecting
data type "String" or "WString" in the block interface editors for OB, FC, FB, and DB. You
cannot create a string in the PLC tags editor.
You can specify the maximum string size in bytes (String) or words (WString) by entering
square brackets after the keyword "String" or "WString" after you select one of those data
types from the data type drop-down list. For example, "MyString String[10]" would specify a
10-byte maximum size for MyString. If you do not include the square brackets with a
maximum size, then 254 is assumed for a string and 65534 for a WString. "MyWString
WString[1000]" would specify a 1000-word WString.
S7-1200 Programmable controller
130
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
The following example defines a String with maximum character count of 10 and current
character count of 3. This means the String currently contains 3 one-byte characters, but
could be expanded to contain up to 10 one-byte characters.
Table 5- 36
Example of a String data type
Total Character Count
Current Character Count
Character 1
Character 2
Character 3
...
Character 10
10
3
'C' (16#43)
'A' (16#41)
'T' (16#54)
...
-
Byte 0
Byte 1
Byte 2
Byte 3
Byte 4
...
Byte 11
The following example defines a WString with maximum character count of 500 and current
character count of 300. This means the String currently contains 300 one-word characters,
but could be expanded to contain up to 500 one-word characters.
Table 5- 37
Example of a WString data type
Total Character Count
Current Character Count
Character 1
500
300
'ä' (16#0084)
Word 0
Word 1
Word 2
Characters
2 to 299
Character
300
ASCII charac- 'M' (16#004D)
ter words
Words 3 to
300
Word 301
...
Character 500
...
-
...
Word 501
ASCII control characters can be used in Char, Wchar, String and WString data. The
following table shows examples of control character syntax.
Table 5- 38
Valid ASCII control characters
Control characters
ASCII Hex
value (Char)
ASCII Hex
value (WChar)
Control function
Examples
$L or $l
16#0A
16#000A
Line feed
'$LText', '$0AText'
$N or $n
16#0A and
16#0D
16#000A and
16#000D
Line break
'$NText',
'$0A$0DText'
$P or $p
16#0C
16#000C
Form feed
'$PText', '$0CText'
$R or $r
16#0D
16#000D
Carriage return (CR)
'$RText','$0DText'
$T or $t
16#09
16#0009
Tab
'$TText', '$09Text'
$$
16#24
16#0024
Dollar sign
'100$$', '100$24'
$'
16#27
16#0027
Single quote
'$'Text$'','$27Text$
27'
The new line shows two
characters in the string.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
131
PLC concepts
5.4 Data types
5.4.6
Array data type
Arrays
You can create an array that contains multiple elements of the same data type. Arrays can
be created in the block interface editors for OB, FC, FB, and DB. You cannot create an array
in the PLC tags editor.
To create an array from the block interface editor, name the array and choose data type
"Array [lo .. hi] of type", then edit "lo", "hi", and "type" as follows:
● lo - the starting (lowest) index for your array
● hi - the ending (highest) index for your array
● type - one of the data types, such as BOOL, SINT, UDINT
Table 5- 39
ARRAY data type rules
Data Type
Array syntax
ARRAY
Name [index1_min..index1_max, index2_min..index2_max] of
•
All array elements must be the same data type.
•
The index can be negative, but the lower limit must be less than or equal to the upper limit.
•
Arrays can have one to six dimensions.
•
Multi-dimensional index min..max declarations are separated by comma characters.
•
Nested arrays, or arrays of arrays, are not allowed.
•
The memory size of an array = (size of one element * total number of elements in array)
Array index
Valid index data types
Array index rules
Constant or variable
USInt, SInt, UInt, Int, UDInt,
DInt
•
Value limits: -32768 to +32767
•
Valid: Mixed constants and variables
•
Valid: Constant expressions
•
Not valid: Variable expressions
Example: array
declarations
Example: array
addresses
ARRAY[1..20] of REAL
One dimension, 20 elements
ARRAY[-5..5] of INT
One dimension, 11 elements
ARRAY[1..2, 3..4] of CHAR
Two dimensions, 4 elements
ARRAY1[0]
ARRAY1 element 0
ARRAY2[1,2]
ARRAY2 element [1,2]
ARRAY3[i,j]
If i =3 and j=4, then ARRAY3 element
[3, 4] is addressed
S7-1200 Programmable controller
132
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
5.4.7
Data structure data type
You can use the data type "Struct" to define a structure of data consisting of other data
types. The struct data type can be used to handle a group of related process data as a single
data unit. A Struct data type is named and the internal data structure declared in the data
block editor or a block interface editor.
Arrays and structures can also be assembled into a larger structure. A structure can be
nested up to eight levels deep. For example, you can create a structure of structures that
contain arrays.
5.4.8
PLC data type
The PLC data type editor lets you define data structures that you can use multiple times in
your program. You create a PLC data type by opening the "PLC data types" branch of the
project tree and double-clicking the "Add new data type" item. On the newly created PLC
data type item, use two single-clicks to rename the default name and double-click to open
the PLC data type editor.
You create a custom PLC data type structure using the same editing methods that are used
in the data block editor. Add new rows for any data types that are necessary to create the
data structure that you want.
If a new PLC data type is created, then the new PLC type name will appear in the data type
selector drop-down lists in the DB editor and code block interface editor.
You can potentially use PLC data types in the following ways:
● As a data type in a code block interface or in data blocks
● As a template for the creation of multiple global data blocks that use the same data
structure
● As a data type for PLC tag declarations the I and Q memory areas of the CPU
For example, a PLC data type could be a recipe for mixing colors. You can then assign this
PLC data type to multiple data blocks. You can adjust the variables within each data block to
create a specific color.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
133
PLC concepts
5.4 Data types
5.4.9
Variant pointer data type
The data type Variant can point to variables of different data types or parameters. The
Variant pointer can point to structures and individual structural components. The Variant
pointer does not occupy any space in memory.
Table 5- 40
Properties of the Variant pointer
Length
(Byte)
Representation
Format
Example entry
0
Symbolic
Operand
MyTag
DB_name.Struct_name.element_name
MyDB.Struct1.pressure1
Operand
%MW10
DB_number.Operand Type Length
P#DB10.DBX10.0 INT 12
Absolute
5.4.10
Accessing a "slice" of a tagged data type
PLC tags and data block tags can be accessed at the bit, byte, or word level depending on
their size. The syntax for accessing such a data slice is as follows:
● "".xn (bit access)
● "".bn (byte access)
● "".wn (word access)
● ""..xn (bit access)
● ""..bn (byte access)
● ""..wn (word access)
A double word-sized tag can be accessed by bits 0 - 31, bytes 0 - 3, or word 0 - 1. A wordsized tag can be accessed by bits 0 - 15, bytes 0 - 1, or word 0. A byte-sized tag can be
accessed by bits 0 - 7, or byte 0. Bit, byte, and word slices can be used anywhere that bits,
bytes, or words are expected operands.
S7-1200 Programmable controller
134
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
Note
Valid data types that can be accessed by slice are Byte, Char, Conn_Any, Date, DInt,
DWord, Event_Any, Event_Att, Hw_Any, Hw_Device, HW_Interface, Hw_Io, Hw_Pwm,
Hw_SubModule, Int, OB_Any, OB_Att, OB_Cyclic, OB_Delay, OB_WHINT, OB_PCYCLE,
OB_STARTUP, OB_TIMEERROR, OB_Tod, Port, Rtm, SInt, Time, Time_Of_Day, UDInt,
UInt, USInt, and Word. PLC Tags of type Real can be accessed by slice, but data block tags
of type Real cannot.
Examples
In the PLC tag table, "DW" is a declared tag of type DWORD. The examples show bit, byte,
and word slice access:
LAD
FBD
Bit access
SCL
IF "DW".x11 THEN
...
END_IF;
Byte access
IF "DW".b2 = "DW".b3
THEN
...
END_IF;
Word access
out:= "DW".w0 AND
"DW".w1;
5.4.11
Accessing a tag with an AT overlay
The AT tag overlay allows you to access an already-declared tag of a standard access block
with an overlaid declaration of a different data type. You can, for example, address the
individual bits of a tag of a Byte, Word, or DWord data type with an Array of Bool.
Declaration
To overlay a parameter, declare an additional parameter directly after the parameter that is
to be overlaid and select the data type "AT". The editor creates the overlay, and you can
then choose the data type, struct, or array that you wish to use for the overlay.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
135
PLC concepts
5.4 Data types
Example
This example shows the input parameters of a standard-access FB. The byte tag B1 is
overlaid with an array of Booleans:
Another example is a DWord tag overlaid with a Struct, which includes a Word, Byte, and
two Booleans:
The Offset column of the block interface shows the location of the overlaid data types
relative to the original tag.
You can address the overlay types directly in the program logic:
LAD
FBD
SCL
IF #OV[1] THEN
...
END_IF;
IF #DW1_Struct.W1 = W#16#000C THEN
...
END_IF;
out1 := #DW1_Struct.B1;
IF #OV[4] AND #DW1_Struct.BO2 THEN
...
END_IF;
S7-1200 Programmable controller
136
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.4 Data types
Rules
● Overlaying of tags is only possible in FB and FC blocks with standard (not optimized)
access.
● You can overlay parameters for all block types and all declaration sections.
● You can use an overlaid parameter like any other block parameter.
● You cannot overlay parameters of type VARIANT.
● The size of the overlaying parameter must be less than or equal to the size of the overlaid
parameter.
● You must declare the overlaying variable immediately after the variable that it overlays
and select the keyword "AT" as the initial data type selection.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
137
PLC concepts
5.5 Using a memory card
5.5
Using a memory card
Note
The CPU supports only the pre-formatted SIMATIC memory cards (Page 1546).
Before you copy any program to the formatted memory card, delete any previously saved
program from the memory card.
Use the memory card either as a transfer card or as a program card. Any program that you
copy to the memory card contains all of the code blocks and data blocks, any technology
objects, and the device configuration. A copied program does not contain force values. The
force values are not part of the program, but are stored in the load memory, whether the
internal load memory of the CPU, or the external load memory (a program card). If you insert
a program card in the CPU, STEP 7 then applies the force values only to the external load
memory on the program card.
● Use a transfer card (Page 142) to copy a program to the internal load memory of the CPU
without using STEP 7. After you insert the transfer card, the CPU first erases the user
program and any force values from the internal load memory, and then copies the
program from the transfer card to the internal load memory. When the transfer process is
complete, you must remove the transfer card.
You can use an empty transfer card to access a password-protected CPU when the
password has been lost or forgotten (Page 151). Inserting the empty transfer card deletes
the password-protected program in the internal load memory of the CPU. You can then
download a new program to the CPU.
● Use a program card (Page 145) as external load memory for the CPU. Inserting a
program card in the CPU erases all of the CPU internal load memory (the user program
and any force values). The CPU then executes the program in external load memory (the
program card). Downloading to a CPU that has a program card updates only the external
load memory (the program card).
Because the internal load memory of the CPU was erased when you inserted the
program card, the program card must remain in the CPU. If you remove the program
card, the CPU goes to STOP mode. (The error LED flashes to indicate that program card
has been removed.)
You also use a memory card when downloading firmware updates (Page 148).
S7-1200 Programmable controller
138
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
5.5.1
Inserting a memory card in the CPU
NOTICE
Protect memory card and receptacle from electrostatic discharge
Electrostatic discharge can damage the memory card or the receptacle on the CPU.
Make contact with a grounded conductive pad and/or wear a grounded wrist strap when
you handle the memory card. Store the memory card in a conductive container.
Check that the memory card is not write-protected. Slide the protection
switch away from the "Lock" position.
Note that if you do insert a write-protected memory card into the CPU,
STEP 7 will display a diagnostic message on the next power up alerting you
to that fact. The CPU will power up without failure, but instructions involving
recipes or data logs, for example, will return errors if the card is writeprotected.
WARNING
Verify that the CPU is not running a process before inserting the memory card.
If you insert a memory card (whether configured as a program card, transfer card, or
firmware update card) into a running CPU, the CPU goes immediately to STOP mode,
which might cause process disruption that could result in death or severe personal injury.
Before inserting or removing a memory card, always ensure that the CPU is not actively
controlling a machine or process. Always install an emergency stop circuit for your
application or process.
Note
Do not insert V3.0 program transfer cards into S7-1200 V4.0 CPUs.
Version 3.0 program transfer cards are not compatible with version S7-1200 V4.0 CPUs.
Inserting a memory card that contains a V3.0 program causes a CPU error.
If you do insert an invalid version program transfer card (Page 142), you should remove the
card, and perform a STOP to RUN transition, a memory reset (MRES), or cycle power. After
you recover the CPU from the error condition, you can download a valid V4.0 CPU program.
To transfer a V3.0 program to a V4.0 program, you must use the TIA Portal to Change
Device in the Hardware Configuration.
Note
If you insert a memory card with the CPU in STOP mode, the diagnostic buffer displays a
message that the memory card evaluation has been initiated. The CPU will evaluate the
memory card the next time you either change the CPU to RUN mode, reset the CPU
memory with an MRES, or power-cycle the CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
139
PLC concepts
5.5 Using a memory card
Table 5- 41
Inserting a memory card
To insert a memory card, open the top CPU
door and insert the memory card in the slot. A
push-push type connector allows for easy
insertion and removal.
The memory card is keyed for proper installation.
CPU behavior when you insert a memory card
When you insert a memory card in the CPU, the CPU peforms the following steps:
1. Transitions to STOP mode (if not already in STOP mode)
2. Prompts for one of the following choices:
– Power cycle
– Transition to RUN mode
– Perform a memory reset
3. Evaluates the card
S7-1200 Programmable controller
140
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
How the CPU evaluates the memory card
If you do not configure the CPU to "Disable copy from internal load memory to external load
memory" in the Protection properties of the device configuration (Page 212), the CPU
determines what type of memory card you inserted:
● Empty memory card: A blank memory card does not have a job file (S7_JOB.S7S). If you
insert a blank memory card, the CPU adds a program job file. It then copies internal load
memory to external load memory (the program file on the memory card) and erases
internal load memory.
● Blank program card: A blank program card has a program job file that is empty. In this
case, the CPU copies internal load memory to external load memory (the program file on
the memory card) and erases internal load memory.
If you configured the CPU to "Disable copy from internal load memory to external load
memory" in the Protection properties of the device configuration, the CPU behaves as
follows:
● Empty memory card: A blank memory card does not have a job file (S7_JOB.S7S). If you
insert a blank memory card, the CPU does nothing. It does not create a program job file
and it does not copy internal load memory to external load memory (the program file on
the memory card). It does not erase internal load memory.
● Blank program card: A blank program card has a program job file that is empty. In this
case, the CPU performs no action. It does not copy internal load memory to external load
memory (the program file on the memory card). It does not erase internal load memory.
If you insert a program card (Page 145), transfer card (Page 142), or card that contains a
firmware update (Page 148)into the CPU, the configuration setting for "Disable copy from
internal load memory to external load memory" has no effect on how the CPU evaluates the
memory card.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
141
PLC concepts
5.5 Using a memory card
5.5.2
Configuring the startup parameter of the CPU before copying the project to the
memory card
When you copy a program to a transfer card or a program card, the program includes the
startup parameter for the CPU. Before copying the program to the memory card, always
ensure that you have configured the operating mode for the CPU following a power-cycle.
Select whether the CPU starts in STOP mode, RUN mode, or in the previous mode (prior to
the power cycle).
5.5.3
Transfer card
NOTICE
Protect memory card and receptacle from electrostatic discharge
Electrostatic discharge can damage the memory card or the receptacle on the CPU.
Make contact with a grounded conductive pad and/or wear a grounded wrist strap
whenever you handle the memory card. Store the memory card in a conductive container.
S7-1200 Programmable controller
142
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
Creating a transfer card
Always remember to configure the startup parameter of the CPU (Page 142) before copying
a program to the transfer card. To create a transfer card, follow these steps:
1. Insert a blank SIMATIC memory card that is not write-protected into an SD card
reader/writer attached to your computer. (If the card is write-protected, slide the
protection switch away from the "Lock" position.)
If you are reusing a SIMATIC memory card that contains a user program, data logs,
recipes, or a firmware update, you must delete the files before reusing the card. Use
Windows Explorer to display the contents of the memory card and delete the
"S7_JOB.S7S" file and also delete any existing folders (such as
"SIMATIC.S7S","FWUPDATE.S7S", "DataLogs", and "Recipes").
NOTICE
Do NOT delete the hidden files "__LOG__" and "crdinfo.bin" from the memory card.
The "__LOG__" and "crdinfo.bin" files are required for the memory card. If you delete
these files, you cannot use the memory card with the CPU.
2. In the Project tree (Project view), expand the "SIMATIC Card Reader" folder and select
your card reader.
3. Display the "Memory card" dialog by right-clicking the drive letter corresponding to the
memory card in the card reader and selecting "Properties" from the context menu.
4. In the "Memory card" dialog, select "Transfer" from the "Card type" drop-down menu.
At this point, STEP 7 creates the empty transfer card. If you are creating an empty
transfer card, such as to recover from a lost CPU password (Page 151), remove the
transfer card from the card reader.
5. Add the program by selecting the CPU device (such as PLC_1 [CPU 1214C DC/DC/DC])
in the Project tree and dragging the CPU device to the memory card. (Another method is
to copy the CPU device and paste it to the memory card.) Copying the CPU device to the
memory card opens the "Load preview" dialog.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
143
PLC concepts
5.5 Using a memory card
6. In the "Load preview" dialog, click the "Load" button to copy the CPU device to the
memory card.
7. When the dialog displays a message that the CPU device (program) has been loaded
without errors, click the "Finish" button.
Using a transfer card
WARNING
Verify that the CPU is not actively running a process before inserting the memory card.
Inserting a memory card will cause the CPU to go to STOP mode, which could affect the
operation of an online process or machine. Unexpected operation of a process or machine
could result in death or injury to personnel and/or property damage.
Before inserting a transfer card, always ensure that the CPU is in STOP mode and your
process is in a safe state.
Note
Do not insert V3.0 program transfer cards into later model CPUs.
Version 3.0 program transfer cards are not compatible with later model S7-1200 CPUs.
Inserting a memory card that contains a V3.0 program causes a CPU error.
If you do insert an invalid version program transfer card, then remove the card, perform a
STOP to RUN transition, a memory reset (MRES), or cycle power. After you recover the
CPU from the error condition, you can download a valid CPU program
To transfer the program to a CPU, follow these steps:
1. Insert the transfer card into the CPU (Page 139). If the CPU is in RUN, the CPU will go to
STOP mode. The maintenance (MAINT) LED flashes to indicate that the memory card
needs to be evaluated.
2. Power-cycle the CPU to evaluate the memory card. Alternative methods for rebooting the
CPU are to perform either a STOP-to-RUN transition or a memory reset (MRES) from
STEP 7.
3. After the rebooting and evaluating the memory card, the CPU copies the program to the
internal load memory of the CPU.
The RUN/STOP LED alternately flashes green and yellow to indicate that the program is
being copied. When the RUN/STOP LED turns on (solid yellow) and the MAINT LED
flashes, the copy process has finished. You can then remove the memory card.
4. Reboot the CPU (either by restoring power or by the alternative methods for rebooting) to
evaluate the new program that was transferred to internal load memory.
The CPU then goes to the start-up mode (RUN or STOP) that you configured for the project.
Note
You must remove the transfer card before setting the CPU to RUN mode.
S7-1200 Programmable controller
144
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
5.5.4
Program card
NOTICE
Electrostatic discharge can damage the memory card or the receptacle on the CPU.
Make contact with a grounded conductive pad and/or wear a grounded wrist strap when
you handle the memory card. Store the memory card in a conductive container.
Check that the memory card is not write-protected. Slide the protection
switch away from the "Lock" position.
Before you copy any program elements to the program card, delete any
previously saved programs from the memory card.
Creating a program card
When used as a program card, the memory card is the external load memory of the CPU. If
you remove the program card, the internal load memory of the CPU is empty.
Note
If you insert a blank memory card into the CPU and perform a memory card evaluation by
either power cycling the CPU, performing a STOP to RUN transition, or performing a
memory reset (MRES), the program and force values in internal load memory of the CPU are
copied to the memory card. (The memory card is now a program card.) After the copy has
been completed, the program in internal load memory of the CPU is then erased. The CPU
then goes to the configured startup mode (RUN or STOP).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
145
PLC concepts
5.5 Using a memory card
Always remember to configure the startup parameter of the CPU (Page 142) before copying
a project to the program card. To create a program card, follow these steps:
1. Insert a blank SIMATIC memory card that is not write-protected into an SD card
reader/writer attached to your computer. (If the card is write-protected, slide the
protection switch away from the "Lock" position.)
If you are reusing a SIMATIC memory card that contains a user program, data logs,
recipes, or a firmware update, you must delete the files before reusing the card. Use
Windows Explorer to display the contents of the memory card and delete the
"S7_JOB.S7S" file and also delete any existing folders (such as
"SIMATIC.S7S","FWUPDATE.S7S", "DataLogs", and "Recipes").
NOTICE
Do NOT delete the hidden files "__LOG__" and "crdinfo.bin" from the memory card.
The "__LOG__" and "crdinfo.bin" files are required for the memory card. If you delete
these files, you cannot use the memory card with the CPU.
2. In the Project tree (Project view), expand the "SIMATIC Card Reader" folder and select
your card reader.
3. Display the "Memory card" dialog by right-clicking the drive letter corresponding to the
memory card in the card reader and selecting "Properties" from the context menu.
4. In the "Memory card" dialog, select "Program" from the drop-down menu.
5. Add the program by selecting the CPU device (such as PLC_1 [CPU 1214C DC/DC/DC])
in the Project tree and dragging the CPU device to the memory card. (Another method is
to copy the CPU device and paste it to the memory card.) Copying the CPU device to the
memory card opens the "Load preview" dialog.
6. In the "Load preview" dialog, click the "Load" button to copy the CPU device to the
memory card.
7. When the dialog displays a message that the CPU device (program) has been loaded
without errors, click the "Finish" button.
S7-1200 Programmable controller
146
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
Using a program card as the load memory for your CPU
WARNING
Risks associated with inserting a program card
Verify that the CPU is not actively running a process before inserting the memory card.
Inserting a memory card will cause the CPU to go to STOP mode, which could affect the
operation of an online process or machine. Unexpected operation of a process or machine
could result in death or injury to personnel and/or property damage.
Before inserting a memory card, always ensure that the CPU is offline and in a safe state.
To use a program card with your CPU, follow these steps:
1. Insert the program card into the CPU. If the CPU is in RUN mode, the CPU goes to STOP
mode. The maintenance (MAINT) LED flashes to indicate that the memory card needs to
be evaluated.
2. Power-cycle the CPU to evaluate the memory card. Alternative methods for rebooting the
CPU are to perform either a STOP-to-RUN transition or a memory reset (MRES) from
STEP 7.
3. After the CPU reboots and evaluates the program card, the CPU erases the internal load
memory of the CPU.
The CPU then goes to the start-up mode (RUN or STOP) that you configured for the CPU.
The program card must remain in the CPU. Removing the program card leaves the CPU with
no program in internal load memory.
WARNING
Risks associated with removing a program card
If you remove the program card, the CPU loses its external load memory and generates an
error. The CPU goes to STOP mode and flashes the error LED.
Control devices can fail in an unsafe condition, resulting in unexpected operation of
controlled equipment. Such unexpected operations could result in death or serious injury to
personnel, and/or damage to equipment.
Do not remove the program card without understanding that you are removing the program
from CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
147
PLC concepts
5.5 Using a memory card
5.5.5
Firmware update
You can use a SIMATIC memory card for performing a firmware update.
NOTICE
Protect memory card and receptacle from electrostatic discharge
Electrostatic discharge can damage the memory card or the receptacle on the CPU.
Make contact with a grounded conductive pad and/or wear a grounded wrist strap
whenever you handle the memory card. Store the memory card in a conductive container.
You use a SIMATIC memory card when downloading firmware updates from Siemens
Industry Online Support (http://support.industry.siemens.com). From this Web site, navigate
to "Downloads". From there search for the specific type of module that you need to update.
Alternatively, you can access the S7-1200 downloads Web page
(https://support.industry.siemens.com/cs/ww/en/ps/13683/dl) directly.
Note
You cannot update an S7-1200 CPU V3.0 or earlier to S7-1200 V4.0 or V4.1 by firmware
update.
You can also perform a firmware update by one of these methods:
● Using the online and diagnostic tools of STEP 7 (Page 1318)
● Using the Web server "Module Information" standard Web page (Page 1023)
● Using the SIMATIC Automation Tool
(https://support.industry.siemens.com/cs/ww/en/view/98161300)
NOTICE
Do not use the Windows formatter utility or any other formatting utility to reformat the
memory card.
If a Siemens memory card is reformatted using the Microsoft Windows formatter utility, then
the memory card will no longer be usable by a S7-1200 CPU.
S7-1200 Programmable controller
148
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.5 Using a memory card
To download the firmware update to your memory card, follow these steps:
1. Insert a blank SIMATIC memory card that is not write-protected into an SD card
reader/writer attached to your computer. (If the card is write-protected, slide the
protection switch away from the "Lock" position.)
You can reuse a SIMATIC memory card that contains a user program or another firmware
update, but you must delete some of the files on the memory card.
To reuse a memory card, you must delete the "S7_JOB.S7S" file and any existing "Data
Logs" folders or any folder (such as "SIMATIC.S7S" or "FWUPDATE.S7S") before
downloading the firmware update. Use Windows Explorer to display the contents of the
memory card and to delete the file and folders.
NOTICE
Do NOT delete the hidden files "__LOG__" and "crdinfo.bin" from the memory card.
The "__LOG__" and "crdinfo.bin" files are required for the memory card. If you delete
these files, you cannot use the memory card with the CPU.
2. Select the zip file for the firmware update that corresponds to your module, and download
it to your computer. Double-click the file, set the file destination path to be the root
directory of the SIMATIC memory card, and start the extraction process. After the
extraction is complete, the root directory (folder) of the memory card will contain a
"FWUPDATE.S7S" directory and the "S7_JOB.S7S" file.
3. Safely eject the card from the card reader/writer.
To install the firmware update, follow these steps:
WARNING
Verify that the CPU is not actively running a process before installing the firmware update.
Installing the firmware update will cause the CPU to go to STOP mode, which could affect
the operation of an online process or machine. Unexpected operation of a process or
machine could result in death or injury to personnel and/or property damage.
Before inserting the memory card, always ensure that the CPU is offline and in a safe state.
1. Insert the memory card into the CPU. If the CPU is in RUN mode, the CPU then goes to
STOP mode. The maintenance (MAINT) LED flashes to indicate that the memory card
needs to be evaluated.
2. Power-cycle the CPU to start the firmware update. Alternative methods for rebooting the
CPU are to perform either a STOP-to-RUN transition or a memory reset (MRES) from
STEP 7.
Note
To complete the firmware upgrade for the module, you must ensure that the external 24 V
DC power to the module remains on.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
149
PLC concepts
5.5 Using a memory card
After the CPU reboots, the firmware update starts. The RUN/STOP LED alternately
flashes green and yellow to indicate that the update is being copied. When the
RUN/STOP LED turns on (solid yellow) and the MAINT LED flashes, the copy process
has finished. You must then remove the memory card.
3. After removing the memory card, reboot the CPU again (either by restoring power or by
the alternative methods for rebooting) to load the new firmware.
The user program and hardware configuration are not affected by the firmware update.
When the CPU is powered up, the CPU enters the configured start-up state. (If the startup
mode for your CPU was configured to "Warm restart - mode before POWER OFF", the CPU
will be in STOP mode because the last state of the CPU was STOP.)
Note
Updating multiple modules connected to CPU
If your hardware configuration contains multiple modules that correspond to a single
firmware update file on the memory card, the CPU applies the updates to all applicable
modules (CM, SM, and SB) in configuration order, that is, by increasing order of the module
position in Device Configuration in STEP 7.
If you have downloaded multiple firmware updates to the memory card for multiple modules,
the CPU applies the updates in the order in which you downloaded them to the memory
card.
S7-1200 Programmable controller
150
System Manual, V4.2, 09/2016, A5E02486680-AK
PLC concepts
5.6 Recovery from a lost password
5.6
Recovery from a lost password
If you have lost the password for a password-protected CPU, use an empty transfer card to
delete the password-protected program. The empty transfer card erases the internal load
memory of the CPU. You can then download a new user program from STEP 7 to the CPU.
For information about the creation and use of an empty transfer card, see the section of
transfer cards (Page 142).
WARNING
Verify that the CPU is not actively running a process before inserting the memory card
If you insert a transfer card in a running CPU, the CPU goes to STOP. Control devices can
fail in an unsafe condition, resulting in unexpected operation of controlled equipment. Such
unexpected operations could result in death or serious injury to personnel, and/or damage
to equipment.
Before inserting a transfer card, always ensure that the CPU is in STOP mode and your
process is in a safe state.
You must remove the transfer card before setting the CPU to RUN mode.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
151
PLC concepts
5.6 Recovery from a lost password
S7-1200 Programmable controller
152
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6
You create the device configuration for your PLC by adding a CPU and additional modules to
your project.
①
②
③
④
⑤
Communication module (CM) or communication processor (CP): Up to 3, inserted in slots 101,
102, and 103
CPU: Slot 1
PROFINET port of CPU
Signal board (SB), communication board (CB) or battery board (BB): up to 1, inserted in the
CPU
Signal module (SM) for digital or analog I/O: up to 8, inserted in slots 2 through 9
(CPU 1214C, CPU 1215C and CPU 1217C allow 8, CPU 1212C allows 2, CPU 1211C does not
allow any)
Configuration control
Device configuration for the S7-1200 also supports "configuration control (Page 159)" where
you can configure a maximum configuration for a project including modules that you might
not actually use. This feature, sometimes also called "option handling", allows you to
configure a maximum configuration that you might use with variations in the installed
modules in multiple applications.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
153
Device configuration
6.1 Inserting a CPU
6.1
Inserting a CPU
You can insert a CPU into your project from either the Portal view or the
Project view of STEP 7:
• In the Portal view, select "Devices
& Networks" and click "Add new
device".
• In the Project view, under the
project name, double-click "Add
new device".
Be sure you insert the correct model and firmware version from the list. Selecting the CPU
from the "Add new device" dialog creates the rack and CPU.
Note
With STEP 7 V14, you cannot add a V1.0 S7-1200 CPU to your project.
S7-1200 Programmable controller
154
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.1 Inserting a CPU
"Add new device" dialog
Device view of the hardware
configuration
Selecting the CPU in the Device
view displays the CPU properties in the inspector window.
The CPU does not have a preconfigured IP address. You must
manually assign an IP address
for the CPU during the device
configuration. If your CPU is
connected to a router on the
network, you also enter the IP
address for a router.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
155
Device configuration
6.2 Uploading the configuration of a connected CPU
6.2
Uploading the configuration of a connected CPU
STEP 7 provides two methods for uploading the hardware configuration of a connected
CPU:
● Uploading the connected device as a new station
● Configuring an unspecified CPU and detecting the hardware configuration of the
connected CPU
Note, however, that the first method uploads both the hardware configuration and the
software of the connected CPU.
Uploading a device as a new station
To upload a connected device as a new station, follow these steps:
1. Expand your communications interface from the "Online access" node of the project tree.
2. Double-click "Update accessible devices".
3. Select the PLC from the detected devices.
4. From the Online menu of STEP 7, select the "Upload device as new station (hardware
and software)" menu command.
STEP 7 uploads both the hardware configuration and the program blocks.
S7-1200 Programmable controller
156
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.2 Uploading the configuration of a connected CPU
Detecting the hardware configuration of an unspecified CPU
If you are connected to a CPU, you can upload the
configuration of that CPU, including any modules, to
your project. Simply create a new project and select
the "unspecified CPU" instead of selecting a specific
CPU. (You can also skip the device configuration entirely by selecting the "Create a PLC program" from the
"First steps". STEP 7 then automatically creates an
unspecified CPU.)
From the program editor, you select the "Hardware
detection" command from the "Online" menu.
From the device configuration editor, you select the option for detecting the configuration of
the connected device.
After you select the CPU from the online dialog and click the Load button, STEP 7 uploads
the hardware configuration from the CPU, including any modules (SM, SB, or CM). You can
then configure the parameters for the CPU and the modules (Page 170).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
157
Device configuration
6.3 Adding modules to the configuration
6.3
Adding modules to the configuration
Use the hardware catalog to add modules to the CPU:
● Signal module (SM) provides additional digital or analog I/O points. These modules are
connected to the right side of the CPU.
● Signal board (SB) provides just a few additional I/O points for the CPU. The SB is
installed on the front of the CPU.
● Battery Board 1297 (BB) provides long-term backup of the realtime clock. The BB is
installed on the front of the CPU.
● Communication board (CB) provides an additional communication port (such as RS485).
The CB is installed on the front of the CPU.
● Communication module (CM) and communication processor (CP) provide an additional
communication port, such as for PROFIBUS or GPRS. These modules are connected to
the left side of the CPU.
To insert a module into the device configuration, select the module in the hardware catalog
and either double-click or drag the module to the highlighted slot. You must add the modules
to the device configuration and download the hardware configuration to the CPU for the
modules to be functional.
Table 6- 1
Module
Adding a module to the device configuration
Select the module
Insert the module
Result
SM
SB, BB
or CB
CM or
CP
S7-1200 Programmable controller
158
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
With the "configuration control" feature (Page 159), you can add signal modules and signal
boards to your device configuration that might not correspond to the actual hardware for a
specific application, but that will be used in related applications that share a common user
program, CPU model, and perhaps some of the configured modules.
6.4
Configuration control
6.4.1
Advantages and applications of configuration control
Configuration control can be a useful solution when you create an automation solution
(machine) that you intend to use with variations in multiple installations.
You can load a STEP 7 device configuration and user program to different installed PLC
configurations. You only need to make a few easy adaptations to make the STEP 7 project
correspond to the actual installation.
6.4.2
Configuring the central installation and optional modules
Configuration control with STEP 7 and the S7-1200 enables you to configure a maximum
configuration for a standard machine and to operate versions (options) that use a subset of
this configuration. The PROFINET with STEP 7 manual
(http://support.automation.siemens.com/WW/view/en/49948856) refers to these types of
projects as "standard machine projects".
A control data record that you program in the startup program block notifies the CPU as to
which modules are missing in the real installation as compared to the configuration or which
modules are located in different slots as compared to the configuration. Configuration control
does not have an impact on the parameter assignment of the modules.
Configuration control gives you the flexibility to vary the installation as long as you can derive
the real configuration from the maximum device configuration in STEP 7.
To activate configuration control and structure the required control data record, follow these
steps:
1. Optionally, reset the CPU to factory settings to ensure that an incompatible control data
record is not present in the CPU.
2. Select the CPU in device configuration in STEP 7.
3. From the Configuration control node in the CPU properties, select the "Enable
reconfiguration of device with user program" check box.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
159
Device configuration
6.4 Configuration control
4. Create a PLC data type to contain the control data record. Configure it as a struct that
includes four USints for configuration control information and additional USints to
correspond to the slots of a maximum S7-1200 device configuration, as follows:
5. Create a data block of the PLC data type that you created.
S7-1200 Programmable controller
160
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
6. In this data block, configure the Block_length, Block_ID, Version, and Subversion as
shown below. Configure the values for the slots based on their presence or absence and
position in your actual installation:
– 0: Configured module is not present in the actual configuration. (The slot is empty.)
– 1 to 9, 101 to 103: The actual slot position for the configured slot
– 255: The STEP 7 device configuration does not include a module in this slot.
Note
Configuration control not available for HSCs and PTOs on the signal board
If you have a signal board in the CPU that you configure for HSCs or PTOs, you must not
disable it with a "0" in Slot_1 of the configuration control data record. Configured HSC and
PTO devices of the CPU are mandatory regarding configuration control.
See Example of configuration control (Page 166) for an explanation of how to assign the
slot values.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
161
Device configuration
6.4 Configuration control
7. In the startup OB, call the extended WRREC (Write data record) instruction to transfer the
control data record that you created to index 196 of hardware ID 33. Use a label and JMP
(jump) instruction to wait for the WRREC instruction to complete.
Network 1:
Network 2:
Note
Configuration control is not in effect until the WRREC instruction transfers the control data
record in the startup OB. If you have enabled configuration control and the CPU does not
have the control data record, it will go to STOP mode when it exits STARTUP mode. Be sure
that you program the startup OB to transfer the control data record.
Module arrangement
The following table shows the slot number assignment:
Slot
Modules
1
Signal board or communication board (CPU annex card)
2 to 9
Signal modules
101 to 103
Communication modules
S7-1200 Programmable controller
162
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
Control data record
A control data record 196 contains the slot assignment and represents the actual
configuration, as shown below:
Byte
Element
Value
Explanation
0
Block length
16
Header
1
Block ID
196
2
Version
5
3
Subversion
0
4
Assignment of CPU annex card
Actual annex card, 0, or 255*
Control element
5
Assignment of configured slot 2
Actual slot, 0, or 255*
...
...
...
12
Assignment of configured slot 9
Actual slot, 0, or 255*
Describes in each element which
real slot in the device is assigned to
the configured slot.
13
Assignment of configured slot 101
Actual slot or 255*
14
Assignment of configured slot 102
Actual slot or 255*
15
Assignment of configured slot 103
Actual slot or 255*
Unlike signal modules, the actual
slot for physically-present communication modules must be the same
as the configured slot.
*Slot values:
0: Configured module is not present in the actual configuration. (The slot is empty.)
1 to 9, 101 to 103: The actual slot position for the configured slot
255: The STEP 7 device configuration does not include a module in this slot.
Note
Alternative to creating a PLC tag type
As an alternative to creating a custom PLC tag type, you can create a data block directly with
all of the structure elements of a control data record. You could even configure multiple
structs in this data block to serve as multiple control data record configurations. Either
implementation is an effective way to transfer the control data record during startup.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
163
Device configuration
6.4 Configuration control
Rules
Observe the following rules:
● Configuration control does not support position changes for communication modules. The
control data record slot positions for slots 101 to 103 must correspond to the actual
installation. If you have not configured a module for the slot in your device configuration,
enter 255 for that slot position in the control data record. If you have configured a module
for the slot, enter the configured slot as the actual slot for that slot position.
● F-I/O modules do not support configuration control. The control data record slot positions
for an F-I/O module must equal the configured slot position for the F-I/O module. If you
attempt to move or delete a configured F-I/O module using the control data record, then
all actually-installed F-I/O modules will raise a "parameter assignment" error and disallow
exchange.
● You cannot have embedded empty (unused) slots between filled (used) slots. For
example, if the actual configuration has a module in slot 4, then the actual configuration
must also have modules in slots 2 and 3. Correspondingly, if the actual configuration has
a communication module in slot 102, then the actual configuration must also have a
module in slot 101.
● If you have enabled configuration control, the CPU is not ready for operation without a
control data record. The CPU returns from startup to STOP if a startup OB does not
transfer a valid control data record. The CPU does not initialize the central I/O in this case
and enters the cause for the STOP mode in the diagnostics buffer.
● The CPU saves a successfully-transferred control data record in retentive memory, which
means that it is not necessary to write the control data record 196 again at a restart if you
have not changed the configuration.
● Each real slot must be present only once in the control data record.
● You can only assign a real slot to one configured slot.
Note
Modifying a configuration
The writing of a control data record with a modified configuration triggers the following
automatic reaction by the CPU: Memory reset with subsequent startup with this modified
configuration.
As a result of this reaction, the CPU deletes the original control data record and saves the
new control data record retentively.
S7-1200 Programmable controller
164
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
Behavior during operation
For the online display and for the display in the diagnostics buffer (module OK or module
faulty), STEP 7 uses the device configuration and not the differing real configuration.
Example: A module outputs diagnostics data. This module is configured in slot 4, but is
actually inserted in slot 3. The online view indicates that configured slot 4 is faulty. In the real
configuration, the module at slot 3 indicates an error by its LED display.
If you have configured modules as missing in the control data record (0 entry), the
automation system behaves as follows:
● Modules designated as not present in the control data record do not supply diagnostics
and their status is always OK. The value status is OK.
● Direct writing access to the outputs or writing access to the process image of outputs that
are not present proceeds with no effect; the CPU reports no access error.
● Direct read access to the inputs or read access to the process image of inputs that are
not present results in a value "0" for each input; the CPU reports no access error.
● Writing a data record to a module that is not present proceeds with no effect; the CPU
reports no error.
● Attempting to read a data record from module that is not present resuls in an error
because the CPU cannot return a valid data record.
Error messages
The CPU returns the following error messages if an error occurs during writing of the control
data record:
Error code
Meaning
16#80B1
Invalid length; the length information in the control data record is not correct.
16#80B5
Configuration control parameters not assigned
16#80E2
Data record was transferred in the wrong OB context. The data record must be transferred in the
startup OB.
16#80B0
Block type (byte 2) of control data record is not equal to 196.
16#80B8
Parameter error; module signals invalid parameters, for example:
•
The control data record attempts to modify the configuration of a communication module or a
communication annex card. The real configuration for communication modules and a communication annex card must equal the STEP 7 configuration.
•
The assigned value for an unconfigured slot in the STEP 7 project is not equal to 255.
•
The assigned value for a configured slot is out of range.
•
The assigned configuration has an "internal" empty slot, for example, slot n is assigned and slot
n-1 is not assigned.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
165
Device configuration
6.4 Configuration control
6.4.3
Example of configuration control
This example describes a configuration consisting of a CPU and three I/O modules.The
module at slot 3 is not present in the first actual installation, so you use configuration control
to "hide" it.
In the second installation, the application includes the module that was initially hidden but
now includes it in the last slot. A modified control data record provides the information about
the slot assignments of the modules.
Example: Actual installation with configured but unused module
The device configuration contains all modules that can be present in an actual installation
(maximum configuration). In this case, the module that is in slot 3 in the device configuration
is not present in the real installation.
Figure 6-1
Device configuration of maximum installation with three signal modules
Figure 6-2
Actual installation with module configured in slot 3 absent, and module configured for slot
4 in actual slot 3
S7-1200 Programmable controller
166
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
To indicate the absence of the missing module, you must configure slot 3 in the control data
record with 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
167
Device configuration
6.4 Configuration control
Example: Actual installation with module subsequently added to a different slot
In the second example, the module in slot 3 of the device configuration is present in the
actual installation but is in slot 4.
Figure 6-3
Device configuration compared to actual installation with modules in slots 3 and 4
swapped
S7-1200 Programmable controller
168
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.4 Configuration control
To correlate the device configuration to the actual installation, edit the control data record to
assign the modules to the correct slot positions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
169
Device configuration
6.5 Changing a device
6.5
Changing a device
You can change the device type of a configured CPU or module. From Device configuration,
right-click the device and select "Change device" from the context menu. From the dialog,
navigate to and select the CPU or module that you want to replace. The Change device
dialog shows you compatibility information between the two devices.
For considerations on changing devices between different CPU versions, refer to
Exchanging a V3.0 CPU for a V4.2 CPU (Page 1571).
6.6
Configuring the operation of the CPU
6.6.1
Overview
To configure the operational parameters for the CPU, select the CPU in the Device view
(blue outline around whole CPU), and use the "Properties" tab of the inspector window.
S7-1200 Programmable controller
170
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.6 Configuring the operation of the CPU
Table 6- 2
CPU properties
Property
Description
PROFINET interface
Sets the IP address for the CPU and time synchronization
DI, DO, and AI
Configures the behavior of the local (on-board) digital and analog I/O (for example, digital
input filter times and digital output reaction to a CPU stop).
High-speed counters
(Page 555) and pulse generators (Page 492)
Enables and configures the high-speed counters (HSC) and the pulse generators used for
pulse-train operations (PTO) and pulse-width modulation (PWM)
Startup (Page 87)
When you configure the outputs of the CPU or signal board as pulse generators (for use with
the PWM or motion control instructions), the corresponding output addresses are removed
from the Q memory and cannot be used for other purposes in your user program. If your
user program writes a value to an output used as a pulse generator, the CPU does not write
that value to the physical output.
Startup after POWER ON: Selects the behavior of the CPU following an off-to-on transition,
such as to start in STOP mode or to go to RUN mode after a warm restart
Supported hardware compatibility: Configures the substitution strategy for all system components (SM, SB, CM, CP and CPU):
•
Allow acceptable substitute
• Allow any substitute (default)
Each module internally contains substitution compatibility requirements based on the number of I/O, electrical compatibility, and other corresponding points of comparison. For example, a 16-channel SM could be an acceptable substitute for an 8-channel SM, but an 8channel SM could not be an acceptable substitute for a 16-channel SM. If you select "Allow
acceptable substitute", STEP 7 enforces the substitution rules; otherwise, STEP 7 allows
any substitution.
Parameter assignment time for distributed I/O: Configures a maximum amount of time (default: 60000 ms) for the distributed I/O to be brought online. (The CMs and CPs receive
power and communication parameters from the CPU during startup. This assignment time
allows time for the I/O connected to the CM or CP to be brought online.)
The CPU goes to RUN as soon as the distributed I/O is online, regardless of the assignment
time. If the distributed I/O has not been brought online within this time, the CPU still goes to
RUN--without the distributed I/O.
Note: If your configuration uses a CM 1243-5 (PROFIBUS master), do not set this parameter
below 15 seconds (15000 ms) to ensure that the module can be brought online.
OBs should be interruptible: Configures whether OB execution (for all OBs) in the CPU is
interruptible or non-interruptible (Page 105)
Cycle (Page 109)
Defines a maximum cycle time or a fixed minimum cycle time
Communication load
Allocates a percentage of the CPU time to be dedicated to communication tasks
System and clock memory
(Page 112)
Enables a byte for "system memory" functions and enables a byte for "clock memory" functions (where each bit toggles on and off at a predefined frequency)
Web server (Page 1001)
Enables and configures the Web server feature
Time of day
Selects the time zone and configures daylight saving time
Multilingual support
(Page 175)
Assigns a project language for the Web server to use for displaying diagnostic buffer entry
texts for each of the possible Web server user interface display languages.
Protection (Page 210)
Sets the read/write protection and passwords for accessing the CPU
Configuration control
(Page 159)
Enables configuring a master device configuration that you can control for different actual
device configurations
Connection resources
(Page 801)
Provides a summary of the communication connection resources that are available for the
CPU and the number of connection resources that have been configured
Overview of addresses
Provides a summary of the I/O addresses that have been configured for the CPU
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
171
Device configuration
6.6 Configuring the operation of the CPU
6.6.2
Configuring digital input filter times
The digital input filters protect your program from responding to unwanted fast changes in
the input signals, as may result from switch contact bounce or electrical noise. The default
filter time of 6.4 ms blocks unwanted transitions from typical mechanical contacts. Different
points in your application can require shorter filter times to detect and respond to inputs from
fast sensors, or longer filter times to block slow contact bounce or longer impulse noise.
An input filter time of 6.4 ms means that a single signal change, from ‘0’ to ‘1’ or from ‘1’ to
‘0’, must continue for approximately 6.4 ms to be detected, and a single high or low pulse
shorter than approximately 6.4 ms is not detected. If an input signal switches between ‘0’
and ‘1’ more rapidly than the filter time, the input point value can change in the user program
when the accumulated duration of new value pulses over old value pulses exceeds the filter
time.
The digital input filter works this way:
● When a "1" is input, it counts up, stopping at the filter time. The image register point
changes from "0" to "1" when the count reaches the filter time.
● When a "0" is input, it counts down, stopping at "0". The image register point changes
from "1" to "0" when the count reaches "0".
● If the input is changing back and forth, the counter will count up some and count down
some. The image register will change when the net accumulation of counts reaches
either the filter time or "0".
● A rapidly-changing signal with more "0’s" than "1’s" will eventually go to "0", and if there
are more "1’s" than "0’s", the image register will eventually change to "1".
Each input point has a single filter configuration that applies to all uses: process inputs,
interrupts, pulse catch, and HSC inputs. To configure input filter times, select "Digital Inputs".
S7-1200 Programmable controller
172
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.6 Configuring the operation of the CPU
The default filter time for the digital inputs is 6.4 ms. You can select a filter time from the
Input filters drop-down list. Valid filter times range from 0.1 us to 20.0 ms.
WARNING
Risks with changes to filter time for digital input channel
If you change the filter time for a digital input channel from a previous setting, a new "0"
level input value may need to stay at "0" for up to 20.0 ms before the filter becomes fully
responsive to new inputs. During this time, short "0" pulse events of duration less than 20.0
ms may not be detected or counted.
This changing of filter times can result in unexpected machine or process operation, which
may cause death or serious injury to personnel, and/or damage to equipment.
To ensure that a new filter time goes immediately into effect, a power cycle of the CPU
must be applied.
Configuring filter times for digital inputs used as HSCs
For inputs that you use as high-speed counters (HSCs), change the input filter time to an
appropriate value to avoid missing counts.
Siemens recommends the following settings:
Type of HSC
Recommended input filter time
1 MHz
0.1 microseconds
100 kHz
0.8 microseconds
30 kHz
3.2 microseconds
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
173
Device configuration
6.6 Configuring the operation of the CPU
6.6.3
Pulse catch
The S7-1200 CPU provides a pulse catch feature for digital input points. The pulse catch
feature allows you to capture high-going pulses or low-going pulses that are of such a short
duration that they would not always be seen when the CPU reads the digital inputs at the
beginning of the scan cycle.
When pulse catch is enabled for an input, a change in state of the input is latched and held
until the next input cycle update. This ensures that a pulse which lasts for a short period of
time will be caught and held until the CPU reads the inputs.
The figure below shows the basic operation of the S7-1200 CPU with and without pulse
catch enabled:
Because the pulse catch function operates on the input after it passes through the input filter,
you must adjust the input filter time so that the pulse is not removed by the filter. The figure
below shows a block diagram of the digital input circuit:
The figure below shows the response of an enabled pulse catch function to various input
conditions. If you have more than one pulse in a given scan, only the first pulse is read. If
you have multiple pulses in a given scan, you should use the rising/falling edge interrupt
events:
S7-1200 Programmable controller
174
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.7 Configuring multilingual support
6.7
Configuring multilingual support
The Multilingual support settings allow you to assign one of two project languages for each
user interface language for the S7-1200 Web server (Page 1001). You can also configure no
project language for a user interface language.
What is a project language?
The project language is the language that the TIA Portal uses to display user-defined project
texts as network comments and block comments.
You select project languages in the TIA Portal from the Tools > Project languages menu
command for the selected project in the project tree.
You can then configure user texts such as network comments and block comments in each
project language from the Tools > Project texts menu command. Then when you change the
TIA Portal user interface language, the network comments, block comments, and other
multilingual project texts display in the corresponding project language. You set the TIA
Portal user interface language from the Options > Settings project language menu
command.
Project languages and project texts are also configurable from the Languages & resources
node of the project tree.
The Web server can use one or two of the STEP 7 project languages for the display of
diagnostic buffer messages.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
175
Device configuration
6.8 Configuring the parameters of the modules
Project language correspondence to user interface language in the Web server
The Web server supports the same user interface languages as the TIA Portal; however, it
only supports up to two project languages. You can configure the Web server to use one of
two project languages for diagnostic buffer text entries depending on the user interface
language of the Web server. You configure these settings in the "Multilingual support"
properties in the device configuration of the CPU. (Network comments and block comments
and other multilingual texts are not visible from the Web server.)
In the Multilingual support properties, the user interface languages on the right are not
editable. They are the pre-defined languages that are available for both the TIA Portal and
for the Web server user interfaces. The "Assign project language" setting is configurable and
can be one of two of your configured project languages, or it can be "None". Because the
S7-1200 CPU only supports two project languages, you cannot configure the project
language to be the same as the user interface language for all of the supported user
interface languages.
In the configuration below, the Web server displays diagnostic buffer entries (Page 1022) in
German when the Web server user interface is German, displays no texts for diagnostic
buffer events when the Web server user interface is Spanish, and displays diagnostic buffer
entries in English for all other languages.
S7-1200 Programmable controller
176
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.8 Configuring the parameters of the modules
6.8
Configuring the parameters of the modules
To configure the operational parameters for the modules, select the module in the Device
view and use the "Properties" tab of the inspector window to configure the parameters for the
module.
Configuring a signal module (SM) or a signal board (SB)
The device configuration for signal modules and signal boards provides the means to
configure the following:
● Digital I/O: You can configure inputs for rising-edge detection or falling-edge detection
(associating each with an event and hardware interrupt) or for "pulse catch" (to stay on
after a momentary pulse) through the next update of the input process image. Outputs
can use a freeze or substitute value.
● Analog I/O: For individual inputs, configure parameters, such as measurement type
(voltage or current), range and smoothing, and to enable underflow or overflow
diagnostics. Analog outputs provide parameters such as output type (voltage or current)
and for diagnostics, such as short circuit (for voltage outputs) or upper/lower limit
diagnostics. You do not configure ranges of analog inputs and outputs in engineering
units on the Properties dialog. You must handle this in your program logic as described in
the topic "Processing of analog values (Page 123)".
● I/O addresses: You configure the start address for the set of inputs and outputs of the
module. You can also assign the inputs and outputs to a process image partition (PIP0,
PIP1, PIP2, PIP3, PIP4) or to automatically update, or to use no process image partition.
See "Execution of the user program" (Page 83) for an explanation of the process image
and process image partitions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
177
Device configuration
6.8 Configuring the parameters of the modules
Configuring a communication interface (CM, CP or CB)
Depending on the type of communication interface, you configure the parameters for the
network.
S7-1200 Programmable controller
178
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.9 Configuring the CPU for communication
6.9
Configuring the CPU for communication
The S7-1200 is designed to solve your communications and networking needs by supporting
not only the simplest of networks but also supporting more complex networks. The S7-1200
also provides tools that allow you to communicate with other devices, such as printers and
weigh scales which use their own communications protocols.
Use the "Network view" of Device configuration to
create the network connections between the devices in your project. After creating the network
connection, use the "Properties" tab of the inspector window to configure the parameters of the
network.
Refer to "Creating a network connection"
(Page 806) for further information.
In the Properties window, select the "Ethernet
addresses" configuration entry. STEP 7 displays
the Ethernet address configuration dialog, which
associates the software project with the IP address of the CPU that will receive that project.
Note: The S7-1200 CPU does not have a preconfigured IP address. You must manually assign
an IP address for the CPU.
Refer to "Assigning Internet Protocol (IP) addresses" (Page 810) for further information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
179
Device configuration
6.10 Time synchronization
For the TCP, ISO-on-TCP, and UDP Ethernet
protocols, use the "Properties" of the instruction
(TSEND_C, TRCV_C, or TCON) to configure the
"Local/Partner" connections.
The figure shows the "Connection properties" of
the "Configuration tab" for an ISO-on-TCP connection.
Refer to "Configuring the Local/Partner connection
path" (Page 807) for further information.
After completing the configuration, download the
project to the CPU. All IP addresses are configured when you download the project.
Refer to "Testing the PROFINET network"
(Page 819) for further information.
Note
To make a connection to your CPU, your network interface card (NIC) and the CPU must be
on the same class of network and on the same subnet. You can either set up your network
interface card to match the default IP address of the CPU, or you can change the IP address
of the CPU to match the network class and subnet of your network interface card.
Refer to "Assigning Internet Protocol (IP) addresses" (Page 810) for information about how
to accomplish this.
S7-1200 Programmable controller
180
System Manual, V4.2, 09/2016, A5E02486680-AK
Device configuration
6.10 Time synchronization
6.10
Time synchronization
The objective of time synchronization of the time-of-day clocks is to have one master clock to
which all other local clocks are synchronized. Not only are the clocks synchronized initially,
but they are re-synchronized periodically to avoid the effects of drift over time.
In the case of the S7-1200 and its local base components, only the CPU and some of the CP
modules have time-of-day clocks that may need to be synchronized. In general, the CPU’s
time-of-day clock can be synchronized to an external master clock. The external master
clock might supply the time of day using an NTP server or through a CP in the local rack of
the S7-1200 that is connected to a SCADA system which includes a master clock.
Refer to S7-1200 CPs (https://support.industry.siemens.com/cs/us/en/ps) at Siemens
Industry Online Support, Product Support for further information on all S7-1200 CPs that
support the Time sychronization function.
Setting the time-of-day clock
There are three ways to set the time-of-day clock in the S7-1200 CPU:
● Using the NTP server (Page 822)
● Using the Engineering System (ES)
● From the user program
● Using an HMI panel
You configure time synchronization of the CP modules to the CPU’s clock by selecting the
"CPU synchronizes the modules of the device." check box as shown in the following figure:
By default, neither time synchronization using the NTP server nor time synchronization of the
CP clocks to the CPU’s clock is enabled.
You configure time synchronization of the CPU’s clock and time synchronization of the CP
clocks independently. Consequently, you can enable time synchronization of the CP clocks
by the CPU when the CPU’s clock is set by any internal or external method.
You can select the update interval using the NTP server. The update interval of the NTP
server is set to 10 seconds by default.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
181
Device configuration
6.10 Time synchronization
When you activate time synchronization in a module, the Engineering Station (ES) prompts
you to select the "CPU synchronizes the modules of the device." if you have not already
selected the check box in the CPU’s "Time synchronization" dialog. The ES also warns you if
you configured more than one master clock source for time synchronization (for example,
you activated time synchronization on more than one CP or on both the CPU and a module).
Note
Activating time synchronization on a CP causes the CP to set the CPU’s clock. Selecting the
"CPU synchronizes the modules of the device" check box in the CPU’s "Time
synchronization" dialog causes the CP modules to automatically synchronize to the CPU’s
clock.
Note
You should assign only one time source for the control system.
S7-1200 Programmable controller
182
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.1
7
Guidelines for designing a PLC system
When designing a PLC system, you can choose from a variety of methods and criteria. The
following general guidelines can apply to many design projects. Of course, you must follow
the directives of your own company's procedures and the accepted practices of your own
training and location.
Table 7- 1
Guidelines for designing a PLC system
Recommended steps
Tasks
Partition your process
or machine
Divide your process or machine into sections that have a level of independence from each other.
These partitions determine the boundaries between controllers and influence the functional description specifications and the assignment of resources.
Create the functional
specifications
Write the descriptions of operation for each section of the process or machine, such as the I/O
points, the functional description of the operation, the states that must be achieved before allowing action for each actuator (such as a solenoid, a motor, or a drive), a description of the operator
interface, and any interfaces with other sections of the process or machine.
Design the safety circuits
Identify any equipment that might require hard-wired logic for safety. Remember that control
devices can fail in an unsafe manner, which can produce unexpected startup or change in the
operation of machinery. Where unexpected or incorrect operation of the machinery could result in
physical injury to people or significant property damage, consider the implementation of electromechanical overrides (which operate independently of the PLC) to prevent unsafe operations.
The following tasks should be included in the design of safety circuits:
Plan system security
•
Identify any improper or unexpected operation of actuators that could be hazardous.
•
Identify the conditions that would assure the operation is not hazardous, and determine how
to detect these conditions independently of the PLC.
•
Identify how the PLC affects the process when power is applied and removed, and also identify how and when errors are detected. Use this information only for designing the normal and
expected abnormal operation. You should not rely on this "best case" scenario for safety purposes.
•
Design the manual or electromechanical safety overrides that block the hazardous operation
independent of the PLC.
•
Provide the appropriate status information from the independent circuits to the PLC so that
the program and any operator interfaces have necessary information.
•
Identify any other safety-related requirements for safe operation of the process.
Determine what level of protection (Page 210) you require for access to your process. You can
password-protect CPUs and program blocks from unauthorized access.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
183
Programming concepts
7.1 Guidelines for designing a PLC system
Recommended steps
Tasks
Specify the operator
stations
Based on the requirements of the functional specifications, create the following drawings of the
operator stations:
Create the configuration drawings
Create a list of symbolic names
•
Overview drawing that shows the location of each operator station in relation to the process
or machine.
•
Mechanical layout drawing of the devices for the operator station, such as display, switches,
and lights.
•
Electrical drawings with the associated I/O of the PLC and signal modules.
Based on the requirements of the functional specification, create configuration drawings of the
control equipment:
•
Overview drawing that shows the location of each PLC in relation to the process or machine.
•
Mechanical layout drawing of each PLC and any I/O modules, including any cabinets and
other equipment.
•
Electrical drawings for each PLC and any I/O modules, including the device model numbers,
communications addresses, and I/O addresses.
Create a list of symbolic names for the absolute addresses. Include not only the physical I/O
signals, but also the other elements (such as tag names) to be used in your program.
S7-1200 Programmable controller
184
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.2 Structuring your user program
7.2
Structuring your user program
When you create a user program for the automation tasks, you insert the instructions for the
program into code blocks:
● An organization block (OB) responds to a specific event in the CPU and can interrupt the
execution of the user program. The default for the cyclic execution of the user program
(OB 1) provides the base structure for your user program. If you include other OBs in your
program, these OBs interrupt the execution of OB 1. The other OBs perform specific
functions, such as for startup tasks, for handling interrupts and errors, or for executing
specific program code at specific time intervals.
● A function block (FB) is a subroutine that is executed when called from another code
block (OB, FB, or FC). The calling block passes parameters to the FB and also identifies
a specific data block (DB) that stores the data for the specific call or instance of that FB.
Changing the instance DB allows a generic FB to control the operation of a set of
devices. For example, one FB can control several pumps or valves, with different
instance DBs containing the specific operational parameters for each pump or valve.
● A function (FC) is a subroutine that is executed when called from another code block (OB,
FB, or FC). The FC does not have an associated instance DB. The calling block passes
parameters to the FC. The output values from the FC must be written to a memory
address or to a global DB.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
185
Programming concepts
7.2 Structuring your user program
Choosing the type of structure for your user program
Based on the requirements of your application, you can choose either a linear structure or a
modular structure for creating your user program:
● A linear program executes all of the instructions for your automation tasks in sequence,
one after the other. Typically, the linear program puts all of the program instructions into
the OB for the cyclic execution of the program (OB 1).
● A modular program calls specific code blocks that perform specific tasks. To create a
modular structure, you divide the complex automation task into smaller subordinate tasks
that correspond to the technological functions of the process. Each code block provides
the program segment for each subordinate task. You structure your program by calling
one of the code blocks from another block.
Linear structure:
Modular structure:
By creating generic code blocks that can be reused within the user program, you can simplify
the design and implementation of the user program. Using generic code blocks has a
number of benefits:
● You can create reusable blocks of code for standard tasks, such as for controlling a pump
or a motor. You can also store these generic code blocks in a library that can be used by
different applications or solutions.
● When you structure the user program into modular components that relate to functional
tasks, the design of your program can be easier to understand and to manage. The
modular components not only help to standardize the program design, but can also help
to make updating or modifying the program code quicker and easier.
● Creating modular components simplifies the debugging of your program. By structuring
the complete program as a set of modular program segments, you can test the
functionality of each code block as it is developed.
● Creating modular components that relate to specific technological functions can help to
simplify and reduce the time involved with commissioning the completed application.
S7-1200 Programmable controller
186
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
7.3
Using blocks to structure your program
By designing FBs and FCs to perform generic tasks, you create modular code blocks. You
then structure your program by having other code blocks call these reusable modules. The
calling block passes device-specific parameters to the called block.
When a code block calls another code block, the CPU executes the program code in the
called block. After execution of the called block is complete, the CPU resumes the execution
of the calling block. Processing continues with execution of the instruction that follows after
the block call.
A
Calling block
B
Called (or interrupting) block
① Program execution
② Instruction or event that initiates the execution of
another block
③ Program execution
④ Block end (returns to calling block)
You can nest the block calls for a more modular structure. In the following example, the
nesting depth is 3: the program cycle OB plus 3 layers of calls to code blocks.
①
②
Start of cycle
Nesting depth
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
187
Programming concepts
7.3 Using blocks to structure your program
7.3.1
Organization block (OB)
Organization blocks provide structure for your program. They serve as the interface between
the operating system and the user program. OBs are event driven. An event, such as a
diagnostic interrupt or a time interval, causes the CPU to execute an OB. Some OBs have
predefined start events and behavior.
The program cycle OB contains your main program. You can include more than one program
cycle OB in your user program. During RUN mode, the program cycle OBs execute at the
lowest priority level and can be interrupted by all other event types. The startup OB does not
interrupt the program cycle OB because the CPU executes the startup OB before going to
RUN mode.
After finishing the processing of the program cycle OBs, the CPU immediately executes the
program cycle OBs again. This cyclic processing is the "normal" type of processing used for
programmable logic controllers. For many applications, the entire user program is located in
a single program cycle OB.
You can create other OBs to perform specific functions, such as for handling interrupts and
errors, or for executing specific program code at specific time intervals. These OBs interrupt
the execution of the program cycle OBs.
Use the "Add new block" dialog to create new OBs in your user program.
Interrupt handling is always
event-driven. When such
an event occurs, the CPU
interrupts the execution of
the user program and calls
the OB that was configured
to handle that event. After
finishing the execution of
the interrupting OB, the
CPU resumes the execution of the user program at
the point of interruption.
The CPU determines the order for handling interrupt events by priority. You can assign
multiple interrupt events to the same priority class. For more information, refer to the topics
on organization blocks (Page 92) and execution of the user program (Page 83).
S7-1200 Programmable controller
188
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
Creating additional OBs
You can create multiple OBs for your user program, even for the program cycle and startup
OB events. Use the "Add new block" dialog to create an OB and enter a name for your OB.
If you create multiple program cycle OBs for your user program, the CPU executes each
program cycle OB in numerical sequence, starting with the program cycle OB with the lowest
number (such as OB 1). For example: after the first program cycle OB (such as OB 1)
finishes, the CPU executes the program cycle OB with the next higher number.
Configuring the properties of an OB
You can modify the properties of an OB. For example, you can configure the OB number or
programming language.
Note
Note that you can assign a process image part number to an OB that corresponds to PIP0,
PIP1, PIP2, PIP3, or PIP4. If you enter a number for the process image part number, the
CPU creates that process image partition. See the topic "Execution of the user program
(Page 83)" for an explanation of the process image partitions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
189
Programming concepts
7.3 Using blocks to structure your program
7.3.2
Function (FC)
A function (FC) is a code block that typically performs a specific operation on a set of input
values. The FC stores the results of this operation in memory locations. For example, use
FCs to perform standard and reusable operations (such as for mathematical calculations) or
technological functions (such as for individual controls using bit logic operations). An FC can
also be called several times at different points in a program. This reuse simplifies the
programming of frequently recurring tasks.
An FC does not have an associated instance data block (DB). The FC uses the local data
stack for the temporary data used to calculate the operation. The temporary data is not
saved. To store data permanently, assign the output value to a global memory location, such
as M memory or to a global DB.
7.3.3
Function block (FB)
A function block (FB) is a code block that uses an instance data block for its parameters and
static data. FBs have variable memory that is located in a data block (DB), or "instance" DB.
The instance DB provides a block of memory that is associated with that instance (or call) of
the FB and stores data after the FB finishes. You can associate different instance DBs with
different calls of the FB. The instance DBs allow you to use one generic FB to control
multiple devices. You structure your program by having one code block make a call to an FB
and an instance DB. The CPU then executes the program code in that FB, and stores the
block parameters and the static local data in the instance DB. When the execution of the FB
finishes, the CPU returns to the code block that called the FB. The instance DB retains the
values for that instance of the FB. These values are available to subsequent calls to the
function block either in the same scan cycle or other scan cycles.
Reusable code blocks with associated memory
You typically use an FB to control the operation for tasks or devices that do not finish their
operation within one scan cycle. To store the operating parameters so that they can be
quickly accessed from one scan to the next, each FB in your user program has one or more
instance DBs. When you call an FB, you also specify an instance DB that contains the block
parameters and the static local data for that call or "instance" of the FB. The instance DB
maintains these values after the FB finishes execution.
By designing the FB for generic control tasks, you can reuse the FB for multiple devices by
selecting different instance DBs for different calls of the FB.
An FB stores the Input, Output, and InOut, and Static parameters in an instance DB.
You can also modify and download the function block interface in RUN mode (Page 1341).
S7-1200 Programmable controller
190
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
Assigning the start value in the instance DB
The instance DB stores both a default value and a start value for each parameter. The start
value provides the value to be used when the FB is executed. The start value can then be
modified during the execution of your user program.
The FB interface also provides a "Default value" column that allows you to assign a new start
value for the parameter as you are writing the program code. This default value in the FB is
then transferred to the start value in the associated instance DB. If you do not assign a new
start value for a parameter in the FB interface, the default value from instance DB is copied
to start value.
Using a single FB with DBs
The following figure shows an OB that calls one FB three times, using a different data block
for each call. This structure allows one generic FB to control several similar devices, such as
motors, by assigning a different instance data block for each call for the different devices.
Each instance DB stores the data (such as speed, ramp-up time, and total operating time)
for an individual device.
In this example, FB 22 controls three separate devices, with DB 201 storing the operational
data for the first device, DB 202 storing the operational data for the second device, and DB
203 storing the operational data for the third device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
191
Programming concepts
7.3 Using blocks to structure your program
7.3.4
Data block (DB)
You create data blocks (DB) in your user program to store data for the code blocks. All of the
program blocks in the user program can access the data in a global DB, but an instance DB
stores data for a specific function block (FB).
The data stored in a DB is not deleted when the execution of the associated code block
comes to an end. There are two types of DBs:
● A global DB stores data for the code blocks in your program. Any OB, FB, or FC can
access the data in a global DB.
● An instance DB stores the data for a specific FB. The structure of the data in an instance
DB reflects the parameters (Input, Output, and InOut) and the static data for the FB. (The
Temp memory for the FB is not stored in the instance DB.)
Note
Although the instance DB reflects the data for a specific FB, any code block can access
the data in an instance DB.
You can also modify and download data blocks in RUN mode (Page 1341).
Read-only data blocks
You can configure a DB as being read-only:
1. Right-click the DB in the project navigator and select "Properties" from the context menu.
2. In the "Properties" dialog, select "Attributes".
3. Select the "Data block write-protected in the device" option and click "OK".
S7-1200 Programmable controller
192
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
Optimized and standard data blocks
You can also configure a data block to be either standard or optimized. A standard DB is
compatible with STEP 7 Classic programming tools and the classic S7-300 and S7-400
CPUs. Data blocks with optimized access have no fixed defined structure. The data
elements contain only a symbolic name in the declaration and no fixed address within the
block. The CPU stores the elements automatically in the available memory area of the block
so that there are no gaps in the memory. This makes for optimal use of the memory
capacity.
To set optimized access for a data block, follow these steps:
1. Expand the program blocks folder in the STEP 7 project tree.
2. Right-click the data block and select "Properties" from the context menu.
3. For the attributes, select "Optimized block access".
Note that optimized block access is the default for new data blocks. If you deselect
"Optimized block access", the block uses standard access.
Note
Block access type for an FB and its instance DB
Be sure that if your FB setting is "Optimized block access" then the setting of the instance
DB for that FB is also "Optimized block access". Similarly if you have not selected
"Optimized block access" for the FB such that the FB is of type standard access, then be
sure that the instance DB is also standard, or not optimized block access.
If you do not have compatible block access types, then changes to the IN/OUT parameter
values of the FB from an HMI during execution of the FB could be lost.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
193
Programming concepts
7.3 Using blocks to structure your program
7.3.5
Creating reusable code blocks
Use the "Add new block"
dialog under "Program
blocks" in the Project navigator to create OBs, FBs,
FCs, and global DBs.
When you create a code
block, you select the programming language for the
block. You do not select a
language for a DB because
it only stores data.
Selecting the "Add new
and open" check box (default) opens the code block
in the Project view.
You can store objects you want to reuse in libraries. For each project, there is a project
library that is connected to the project. In addition to the project library, you can create any
number of global libraries that can be used over several projects. Since the libraries are
compatible with each other, library elements can be copied and moved from one library to
another.
Libraries are used, for example, to create templates for blocks that you first paste into the
project library and then further develop there. Finally, you copy the blocks from the project
library to a global library. You make the global library available to other colleagues working
on your project. They use the blocks and further adapt them to their individual requirements,
where necessary.
For details about library operations, refer to the STEP 7 online Help library topics.
S7-1200 Programmable controller
194
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
7.3.6
Passing parameters to blocks
Function Blocks (FB) and Functions (FC) have three different interface types:
● IN
● IN/OUT
● OUT
FBs and FCs receive parameters through the IN and IN/OUT interface types. The blocks
process the parameters and return values to the caller through the IN/OUT and OUT
interface types.
The user program transfers parameters using one of two methods.
Call-by-value
When the user program passes a parameter to a function as "call-by-value", the user
program copies the actual parameter value into the input parameter of the block for the IN
interface type. This operation requires additional memory for the copied value.
When the user program calls the block, it copies the values.
Call-by-reference
When the user program passes a parameter to a function as "call-by-reference", the user
program references the address of the actual parameter for the IN/OUT interface type and
does not copy the value. This operation does not require additional memory.
When the user program calls the block, it references the address of the actual parameters.
Note
Generally, use the IN/OUT interface type for structured tags (for example, ARRAY,
STRUCT, and STRING) in order to avoid increasing the required data memory
unnecessarily.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
195
Programming concepts
7.3 Using blocks to structure your program
Block optimization and passing parameters
The user program passes FC parameters as "call-by-value" for simple data types (for
example, INT, DINT, and REAL). It passes complex data types (for example, STRUCT,
ARRAY, and STRING) as "call-by-reference".
The user program normally passes FB parameters in the instance Data block (DB)
associated with the FB:
● The user program passes simple data types (for example, INT, DINT, and REAL) as "callby-value" by copying the parameters to/from the instance DB.
● The user program copies complex data types (for example, STRUCT, ARRAY, and
STRING) to and from the instance DB for IN and OUT parameter types.
● The user program passes complex data types as "call-by-reference" for the IN/OUT
interface type.
DBs can be created as either "Optimized" or "Standard" (non-optimized). The optimized data
blocks are more compact than the non-optimized data blocks. Also, the ordering of the data
elements within the DB is different for optimized versus non-optimized DBs. Refer to the
"Optimized blocks" section of the S7-Programming Guideline for S7-1200/1500, STEP 7 (TIA
Portal), 03/2014 (http://support.automation.siemens.com/WW/view/en/81318674) for a
discussion of optimized blocks.
You create FBs and FCs to process either optimized or non-optimized data. You can select
the "Optimized block access" check box as one of the attributes for the block. The user
program optimizes program blocks by default, and the program blocks expect data passed to
the block to be in the optimized format.
When the user program passes a complex parameter (for example, a STRUCT) to a
function, the system checks the optimization setting of the data block containing the structure
and the optimization setting of the program block. If you optimize both the data block and the
function, then the user program passes the STRUCT as a "call-by-reference". The same is
true if you select non-optimized for both the data block and the function.
However, if you make the function and data block optimization different (meaning that you
optimized one block and not the other block), the STRUCT must be converted to the format
expected by the function. For example, if you select non-optimized for the data block and
optimized for the function, then a STRUCT in the data block must be converted to an
optimized format before the function can process the STRUCT. The system does this
conversion by making a "copy" of the STRUCT and converting it to the optimized format that
the function expects.
In summary, when the user program passes a complex data type (for example, a STRUCT)
to a function as an IN/OUT parameter, the function expects the user program to pass the
STRUCT as a "call-by-reference":
● If you select optimized or non-optimized for both the data block containing the STRUCT
and the function, the user program passes the data as "call-by-reference".
● If you do not configure the data block and the function with the same optimization settings
(one is optimized and the other is non-optimized), the system must make a copy of the
STRUCT before passing it to the function. Because the system has to make this copy of
the structure, this converts the "call-by-reference", effectively, into a "call-by-value".
S7-1200 Programmable controller
196
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.3 Using blocks to structure your program
Effect of optimization settings on user programs
The copying of the parameter can cause an issue in a user program if an HMI or interrupt
OB modifies elements of the structure. For example, there is an IN/OUT parameter of a
function (normally passed as "call-by-reference"), but the optimization settings of the data
block and function are different:
1. When the user program is ready to call the function, the system must make a "copy" of
the structure to change the format of the data to match the function.
2. The user program calls the function with a reference to the "copy" of the structure.
3. An interrupt OB occurs while the function is executing, and the interrupt OB changes a
value in the original structure.
4. The function completes and, since the structure is an IN/OUT parameter, the system
copies the values back to the original structure in the original format.
The effect of making the copy of the structure to change the format is that the data written by
the interrupt OB is lost. The same can happen when writing a value with an HMI. The HMI
can interrupt the user program and write a value in the same manner as an interrupt OB.
There are multiple ways to correct this issue:
● The best solution for this this issue is to match the optimization settings of the program
block and the data block when using complex data types (for example, a STRUCT). This
ensures that the user program always passes the parameters as "call-by-reference".
● Another solution is that an interrupt OB or HMI does not directly modify an element in the
structure. The OB or HMI can modify another variable, and then you can copy this
variable into the structure at a specific point in the user program.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
197
Programming concepts
7.4 Understanding data consistency
7.4
Understanding data consistency
The CPU maintains the data consistency for all of the elementary data types (such as Words
or DWords) and all of the system-defined structures (for example, IEC_TIMERS or DTL).
The reading or writing of the value cannot be interrupted. (For example, the CPU protects
the access to a DWord value until the four bytes of the DWord have been read or written.) To
ensure that the program cycle OBs and the interrupt OBs cannot write to the same memory
location at the same time, the CPU does not execute an interrupt OB until the read or write
operation in the program cycle OB has been completed.
If your user program shares multiple values in memory between a program cycle OB and an
interrupt OB, your user program must also ensure that these values are modified or read
consistently. You can use the DIS_AIRT (disable alarm interrupt) and EN_AIRT (enable
alarm interrupt) instructions in your program cycle OB to protect any access to the shared
values.
● Insert a DIS_AIRT instruction in the code block to ensure that an interrupt OB cannot be
executed during the read or write operation.
● Insert the instructions that read or write the values that could be altered by an interrupt
OB.
● Insert an EN_AIRT instruction at the end of the sequence to cancel the DIS_AIRT and
allow the execution of the interrupt OB.
A communication request from an HMI device or another CPU can also interrupt execution of
the program cycle OB. The communication requests can also cause problems with data
consistency. The CPU ensures that the elementary data types are always read and written
consistently by the user program instructions. Because the user program is interrupted
periodically by communications, it is not possible to guarantee that multiple values in the
CPU will all be updated at the same time by the HMI. For example, the values displayed on a
given HMI screen could be from different scan cycles of the CPU.
The PtP (Point-to-Point) instructions, PROFINET instructions (such as TSEND_C and
TRCV_C), PROFINET Distributed I/O instructions (Page 384), and PROFIBUS Distributed
I/O Instructions (Page 384) transfer buffers of data that could be interrupted. Ensure the data
consistency for the buffers of data by avoiding any read or write operation to the buffers in
both the program cycle OB and an interrupt OB. If it is necessary to modify the buffer values
for these instructions in an interrupt OB, use a DIS_AIRT instruction to delay any interruption
(an interrupt OB or a communication interrupt from an HMI or another CPU) until an
EN_AIRT instruction is executed.
Note
The use of the DIS_AIRT instruction delays the processing of interrupt OBs until the
EN_AIRT instruction is executed, affecting the interrupt latency (time from an event to the
time when the interrupt OB is executed) of your user program.
S7-1200 Programmable controller
198
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
7.5
Programming language
STEP 7 provides the following standard programming languages for S7-1200:
● LAD (ladder logic) is a graphical programming language. The representation is based on
circuit diagrams (Page 199).
● FBD (Function Block Diagram) is a programming language that is based on the graphical
logic symbols used in Boolean algebra (Page 200).
● SCL (structured control language) is a text-based, high-level programming language
(Page 201).
When you create a code block, you select the programming language to be used by that
block.
Your user program can utilize code blocks created in any or all of the programming
languages.
7.5.1
Ladder logic (LAD)
The elements of a circuit diagram, such as normally closed and normally open contacts, and
coils are linked to form networks.
To create the logic for complex operations, you can insert branches to create the logic for
parallel circuits. Parallel branches are opened downwards or are connected directly to the
power rail. You terminate the branches upwards.
LAD provides "box" instructions for a variety of functions, such as math, timer, counter, and
move.
STEP 7 does not limit the number of instructions (rows and columns) in a LAD network.
Note
Every LAD network must terminate with a coil or a box instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
199
Programming concepts
7.5 Programming language
Consider the following rules when creating a LAD network:
● You cannot create a branch that could result in a power flow in the reverse direction.
● You cannot create a branch that would cause a short circuit.
7.5.2
Function Block Diagram (FBD)
Like LAD, FBD is also a graphical programming language. The representation of the logic is
based on the graphical logic symbols used in Boolean algebra.
To create the logic for complex operations,
insert parallel branches between the boxes.
Mathematical functions and other complex functions can be represented directly in
conjunction with the logic boxes.
STEP 7 does not limit the number of instructions (rows and columns) in an FBD network.
S7-1200 Programmable controller
200
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
7.5.3
SCL
Structured Control Language (SCL) is a high-level, PASCAL-based programming language
for the SIMATIC S7 CPUs. SCL supports the block structure of STEP 7 (Page 187). Your
project can include program blocks in any of the three programming languages: SCL, LAD,
and FBD.
SCL instructions use standard programming operators, such as for assignment (:=),
mathematical functions (+ for addition, - for subtraction, * for multiplication, and / for division).
SCL also uses standard PASCAL program control operations, such as IF-THEN-ELSE,
CASE, REPEAT-UNTIL, GOTO and RETURN. You can use any PASCAL reference for
syntactical elements of the SCL programming language. Many of the other instructions for
SCL, such as timers and counters, match the LAD and FBD instructions. For more
information about specific instructions, refer to the specific instructions in the chapters for
Basic instructions (Page 227) and Extended instructions (Page 335).
7.5.3.1
SCL program editor
You can designate any type of block (OB, FB, or FC) to use the SCL programming language
at the time you create the block. STEP 7 provides an SCL program editor that includes the
following elements:
● Interface section for defining the parameters of the code block
● Code section for the program code
● Instruction tree that contains the SCL instructions supported by the CPU
You enter the SCL code for your instruction directly in the code section. The editor includes
buttons for common code constructs and comments. For more complex instructions, simply
drag the SCL instructions from the instruction tree and drop them into your program. You can
also use any text editor to create an SCL program and then import that file into STEP 7.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
201
Programming concepts
7.5 Programming language
In the Interface section of the SCL code block you can declare the following types of
parameters:
● Input, Output, InOut, and Ret_Val: These parameters define the input tags, output tags,
and return value for the code block. The tag name that you enter here is used locally
during the execution of the code block. You typically would not use the global tag name in
the tag table.
● Static (FBs only; the illustration above is for an FC): The code block uses static tags for
storage of static intermediate results in the instance data block. The block retains static
data until overwritten, which can be after several cycles. The names of the blocks, which
this block calls as multi-instance, are also stored in the static local data.
● Temp: These parameters are the temporary tags that are used during the execution of
the code block.
● Constant: These are named constant values for your code block.
If you call the SCL code block from another code block, the parameters of the SCL code
block appear as inputs or outputs.
In this example, the tags for "Start" and "On" (from the project tag table) correspond to
"StartStopSwitch" and "RunYesNo" in the declaration table of the SCL program.
7.5.3.2
SCL expressions and operations
Constructing an SCL expression
An SCL expression is a formula for calculating a value. The expression consists of operands
and operators (such as *, /, + or -). The operands can be tags, constants, or expressions.
The evaluation of the expression occurs in a certain order, which is defined by the following
factors:
● Every operator has a pre-defined priority, with the highest-priority operation performed
first.
● For operators with equal priority, the operators are processed in a left-to-right sequence.
● You use parentheses to designate a series of operators to be evaluated together.
S7-1200 Programmable controller
202
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
The result of an expression can be used either for assigning a value to a tag used by your
program, as a condition to be used by a control statement, or as parameters for another SCL
instruction or for calling a code block.
Table 7- 2
Operators in SCL
Type
Operation
Operator
Priority
Parentheses
(Expression)
(,)
1
Math
Comparison
Bit logic
Assignment
Power
**
2
Sign (unary plus)
+
3
Sign (unary minus)
-
3
Multiplication
*
4
Division
/
4
Modulo
MOD
4
Addition
+
5
Subtraction
-
5
Less than
<
6
Less than or equal to
<=
6
Greater than
>
6
Greater than or equal to
>=
6
Equal to
=
7
Not equal to
<>
7
Negation (unary)
NOT
3
AND logic operation
AND or &
8
Exclusive OR logic operation
XOR
9
OR logic operation
OR
10
Assignment
:=
11
As a high-level programming language, SCL uses standard statements for basic tasks:
● Assignment statement: :=
● Mathematical functions: +, -, *, and /
● Addressing of global variables (tags): "" (Tag name or data block name
enclosed in double quotes)
● Addressing of local variables: # (Variable name preceded by "#" symbol)
The following examples show different expressions for different uses:
"C" := #A+#B;
"Data_block_1".Tag := #A;
IF #A > #B THEN "C" := #A;
"C" := SQRT (SQR (#A) + SQR (#B));
Assigns the sum of two local variables to a tag
Assignment to a data block tag
Condition for the IF-THEN statement
Parameters for the SQRT instruction
Arithmetic operators can process various numeric data types. The data type of the result is
determined by the data type of the most-significant operands. For example, a multiplication
operation that uses an INT operand and a REAL operand yields a REAL value for the result.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
203
Programming concepts
7.5 Programming language
Control statements
A control statement is a specialized type of SCL expression that performs the following
tasks:
● Program branching
● Repeating sections of the SCL program code
● Jumping to other parts of the SCL program
● Conditional execution
The SCL control statements include IF-THEN, CASE-OF, FOR-TO-DO, WHILE-DO,
REPEAT-UNTIL, CONTINUE, GOTO, and RETURN.
A single statement typically occupies one line of code. You can enter multiple statements on
one line, or you can break a statement into several lines of code to make the code easier to
read. Separators (such as tabs, line breaks and extra spaces) are ignored during the syntax
check. An END statement terminates the control statement.
The following examples show a FOR-TO-DO control statement. (Both forms of coding are
syntactically valid.)
FOR x := 0 TO max DO sum := sum + value(x); END_FOR;
FOR x := 0 TO max DO
sum := sum + value(x);
END_FOR;
A control statement can also be provided with a label. A label is set off by a colon at the
beginning of the statement:
Label: ;
The STEP 7 online help provides a complete SCL programming language reference.
Conditions
A condition is a comparison expression or a logical expression whose result is of type BOOL
(with the value of either TRUE or FALSE). The following example shows conditions of
various types:
#Temperature > 50
#Counter <= 100
#CHAR1 < 'S'
(#Alpha <> 12) AND NOT #Beta
5 + #Alpha
Relational expression
Comparison and logical expression
Arithmetic expression
A condition can use arithmetic expressions:
● The condition of the expression is TRUE if the result is any value other than zero.
● The condition of the expression is FALSE if the result equals zero.
S7-1200 Programmable controller
204
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
Calling other code blocks from your SCL program
To call another code block in your user program, simply enter the name (or absolute
address) of the FB or FC with the parameters. For an FB, you must provide the instance DB
to be called with the FB.
(Parameter list)
Call as a single instance
<#Instance name> (Parameter list)
"MyDB"(MyInput:=10, MyInOut:="Tag1");
(Parameter list)
:= (Parameter list)
"MyFC"(MyInput:=10, MyInOut:="Tag1");
Call as multi-instance
Standard call
Call in an expression
You can also drag blocks from the navigation tree to the SCL program editor, and complete
the parameter assignment.
Adding block comments to SCL code
You can include a block comment in your SCL code by including the comment text between
(* and *). You can have any number of comment lines between the (* and the *). Your SCL
program block can include many block comments. For programming convenience, the SCL
editor includes a block comment button along with common control statements:
Addressing
As with LAD and FBD, SCL allows you to use either tags (symbolic addressing) or absolute
addresses in your user program. SCL also allows you to use a variable as an array index.
Absolute addressing
%I0.0
%MB100
Precede absolute addresses with the "%" symbol.
Without the "%", STEP 7 generates an undefined
tag error at compile time.
Symbolic addressing
"PLC_Tag_1"
"Data_block_1".Tag_1
"Data_block_1".MyArray[#i]
Tag in PLC tag table
Tag in a data block
Array element in a data block array
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
205
Programming concepts
7.5 Programming language
7.5.3.3
Indexed addressing with PEEK and POKE instructions
SCL provides PEEK and POKE instructions that allow you to read from or write to data
blocks, I/O, or memory. You provide parameters for specific byte offsets or bit offsets for the
operation.
Note
To use the PEEK and POKE instructions with data blocks, you must use standard (not
optimized) data blocks. Also note that the PEEK and POKE instructions merely transfer data.
They have no knowledge of data types at the addresses.
PEEK(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
Reads the byte referenced by byteOffset of
the referenced data block, I/O or memory
area.
Example referencing data block:
%MB100 := PEEK(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Example referencing IB3 input:
PEEK_WORD(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
%MB100 := PEEK(area:=16#81,
dbNumber:=0, byteOffset:=#i); // when
#i = 3
Reads the word referenced by byteOffset of
the referenced data block, I/O or memory
area.
Example:
PEEK_DWORD(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
%MW200 := PEEK_WORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Reads the double word referenced by
byteOffset of the referenced data block, I/O or
memory area.
Example:
PEEK_BOOL(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
bitOffset:=_in_);
%MD300 := PEEK_DWORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Reads a Boolean referenced by the bitOffset
and byteOffset of the referenced data block,
I/O or memory area
Example:
%MB100.0 := PEEK_BOOL(area:=16#84,
dbNumber:=1, byteOffset:=#ii,
bitOffset:=#j);
S7-1200 Programmable controller
206
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
POKE(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
value:=_in_);
Writes the value (Byte, Word, or DWord) to
the referenced byteOffset of the referenced
data block, I/O or memory area
Example referencing data block:
POKE(area:=16#84, dbNumber:=2,
byteOffset:=3, value:="Tag_1");
Example referencing QB3 output:
POKE_BOOL(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
bitOffset:=_in_,
value:=_in_);
POKE_BLK(area_src:=_in_,
dbNumber_src:=_in_,
byteOffset_src:=_in_,
area_dest:=_in_,
dbNumber_dest:=_in_,
byteOffset_dest:=_in_,
count:=_in_);
POKE(area:=16#82, dbNumber:=0,
byteOffset:=3, value:="Tag_1");
Writes the Boolean value to the referenced
bitOffset and byteOffset of the referenced
data block, I/O or memory area
Example:
POKE_BOOL(area:=16#84, dbNumber:=2,
byteOffset:=3, bitOffset:=5, value:=0);
Writes "count" number of bytes starting at the
referenced byte Offset of the referenced
source data block, I/O or memory area to the
referenced byteOffset of the referenced destination data block, I/O or memory area
Example:
POKE_BLK(area_src:=16#84,
dbNumber_src:=#src_db, byteOffset_src:=#src_byte, area_dest:=16#84,
dbNumber_dest:=#src_db, byteOffset_dest:=#src_byte, count:=10);
For PEEK and POKE instructions, the following values for the "area", "area_src" and
"area_dest" parameters are applicable. For areas other than data blocks, the dbNumber
parameter must be 0.
16#81
I
16#82
Q
16#83
M
16#84
DB
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
207
Programming concepts
7.5 Programming language
7.5.4
EN and ENO for LAD, FBD and SCL
Determining "power flow" (EN and ENO) for an instruction
Certain instructions (such as the Math and the Move instructions) provide parameters for EN
and ENO. These parameters relate to power flow in LAD or FBD and determine whether the
instruction is executed during that scan. SCL also allows you to set the ENO parameter for a
code block.
● EN (Enable In) is a Boolean input. Power flow (EN = 1) must be present at this input for
the box instruction to be executed. If the EN input of a LAD box is connected directly to
the left power rail, the instruction will always be executed.
● ENO (Enable Out) is a Boolean output. If the box has power flow at the EN input and the
box executes its function without error, then the ENO output passes power flow
(ENO = 1) to the next element. If an error is detected in the execution of the box
instruction, then power flow is terminated (ENO = 0) at the box instruction that generated
the error.
Table 7- 3
Operands for EN and ENO
Program editor
Inputs/outputs
Operands
Data type
LAD
EN, ENO
Power flow
Bool
FBD
EN
I, I:P, Q, M, DB, Temp, Power Flow
Bool
ENO
Power Flow
Bool
EN1
TRUE, FALSE
Bool
ENO2
TRUE, FALSE
Bool
SCL
1
The use of EN is only available for FBs.
2
The use of ENO with the SCL code block is optional. You must configure the SCL compiler to set
ENO when the code block finishes.
Configuring SCL to set ENO
To configure the SCL compiler for setting ENO, follow these steps:
1. Select the "Settings" command from the "Options" menu.
2. Expand the "PLC programming" properties and select "SCL (Structured Control
Language)".
3. Select the "Set ENO automatically" option.
S7-1200 Programmable controller
208
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.5 Programming language
Using ENO in program code
You can also use ENO in your program code, for example by assigning ENO to a PLC tag,
or by evaluating ENO in a local block.
Examples:
“MyFunction”
( IN1 := … ,
IN2 := … ,
OUT1 => #myOut,
ENO => #statusFlag ); // PLC tag statusFlag holds the value of E
NO
“MyFunction”
( IN1 := …
IN2 := … ,
OUT1 => #myOut,
ENO => ENO ); // block status flag of "MyFunction"
// is stored in the local block
IF ENO = TRUE THEN
// execute code only if MyFunction returns true ENO
Effect of Ret_Val or Status parameters on ENO
Some instructions, such as the communication instructions or the string conversion
instructions, provide an output parameter that contains information about the processing of
the instruction. For example, some instructions provide a Ret_Val (return value) parameter,
which is typically an Int data type that contains status information in a range from -32768 to
+32767. Other instructions provide a Status parameter, which is typically a Word data type
that stores status information in a range of hexadecimal values from 16#0000 to 16#FFFF.
The numerical value stored in a Ret_Val or a Status parameter determines the state of ENO
for that instruction.
● Ret_Val: A value from 0 to 32767 typically sets ENO = 1 (or TRUE). A value from -32768
to -1 typically sets ENO = 0 (or FALSE). To evaluate Ret_Val, change the representation
to hexadecimal.
● Status: A value from 16#0000 16#7FFF typically sets ENO = 1 (or TRUE). A value from
16#8000 to 16#FFFF typically sets ENO = 0 (or FALSE).
Instructions that take more than one scan to execute often provide a Busy parameter (Bool)
to signal that the instruction is active but has not completed execution. These instructions
often also provide a Done parameter (Bool) and an Error parameter (Bool). Done signals that
the instruction was completed without error, and Error signals that the instruction was
completed with an error condition.
● When Busy = 1 (or TRUE), ENO = 1 (or TRUE).
● When Done = 1 (or TRUE), ENO = 1 (or TRUE).
● When Error = 1 (or TRUE), ENO = 0 (or FALSE).
See also
OK (Check validity) and NOT_OK (Check invalidity) (Page 252)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
209
Programming concepts
7.6 Protection
7.6
Protection
7.6.1
Access protection for the CPU
The CPU provides four levels of security for restricting access to specific functions. When
you configure the security level and password for a CPU, you limit the functions and memory
areas that can be accessed without entering a password.
Each level allows certain functions to be accessible without a password. The default
condition for the CPU is to have no restriction and no password-protection. To restrict access
to a CPU, you configure the properties of the CPU and enter the password.
Entering the password over a network does not compromise the password protection for the
CPU. Password protection does not apply to the execution of user program instructions
including communication functions. Entering the correct password provides access to all of
the functions at that level.
PLC-to-PLC communications (using communication instructions in the code blocks) are not
restricted by the security level in the CPU.
Table 7- 4
Security levels for the CPU
Security level
Access restrictions
Full access (no
protection)
Allows full access without password protection.
Read access
Allows HMI access, comparing Offline/Online code blocks, and all forms of PLCto-PLC communications without password protection.
Password is required for modifying (writing to) the CPU. Password is not required for changing the CPU mode (RUN/STOP).
HMI access
Allows HMI access and all forms of PLC-to-PLC communications without password protection.
Password is required for reading the data in the CPU, for comparing Offline/Online code blocks, for modifying (writing to) the CPU, and for changing the
CPU mode (RUN/STOP).
No access (complete protection)
Allows no access without password protection.
Password is required for HMI access, reading the data in the CPU, comparing
Offline/Online code blocks, and for modifying (writing to) the CPU.
S7-1200 Programmable controller
210
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.6 Protection
Passwords are case-sensitive. To configure the protection level and passwords, follow these
steps:
1. In the "Device configuration", select the CPU.
2. In the inspector window, select the "Properties" tab.
3. Select the "Protection" property to select the protection level and to enter passwords.
When you download this configuration to the CPU, the user has HMI access and can access
HMI functions without a password. To read data or compare Offline/Online code blocks, the
user must enter the configured password for "Read access" or the password for "Full access
(no protection)". To write data, the user must enter the configured password for "Full access
(no protection)".
WARNING
Unauthorized access to a protected CPU
Users with CPU full access privileges have privileges to read and write PLC variables.
Regardless of the access level for the CPU, Web server users can have privileges to read
and write PLC variables. Unauthorized access to the CPU or changing PLC variables to
invalid values could disrupt process operation and could result in death, severe personal
injury and/or property damage.
Authorized users can perform operating mode changes, writes to PLC data, and firmware
updates. Siemens recommends that you observe the following security practices:
• Password protect CPU access levels and Web server user IDs (Page 1005) with strong
passwords. Strong passwords are at least ten characters in length, mix letters, numbers,
and special characters, are not words that can be found in a dictionary, and are not
names or identifiers that can be derived from personal information. Keep the password
secret and change it frequently.
• Enable access to the Web server only with the HTTPS protocol.
• Do not extend the default minimum privileges of the Web server "Everybody" user.
• Perform error-checking and range-checking on your variables in your program logic
because Web page users can change PLC variables to invalid values.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
211
Programming concepts
7.6 Protection
Connection mechanisms
To access remote connection partners with PUT/GET instructions, the user must also have
permission.
By default, the "Permit access with PUT/GET communication" option is not enabled. In this
case, read and write access to CPU data is only possible for communication connections
that require configuration or programming both for the local CPU and for the communication
partner. Access through BSEND/BRCV instructions is possible, for example.
Connections for which the local CPU is only a server (meaning that no
configuration/programming of the communication with the communication partner exists at
the local CPU), are therefore not possible during operation of the CPU, for example:
● PUT/GET, FETCH/WRITE or FTP access through communication modules
● PUT/GET access from other S7 CPUs
● HMI access through PUT/GET communication
If you want to allow access to CPU data from the client side, that is, you do not want to
restrict the communication services of the CPU, follow these steps:
1. Configure the protection access level to be any level other than "No access (complete
protection)".
2. Select the "Permit access with PUT/GET communication" check box.
When you download this configuration to the CPU, the CPU permits PUT/GET
communication from remote partners
7.6.2
External load memory
You can also protect the external load memory (memory card) from copies. To prevent the
copying of internal load memory to external load memory follow these steps:
1. From the device configuration of the CPU in STEP 7, select "Protection" from the General
properties.
2. In the "External Load Memory" section, select "Disable copy from internal load memory to
external load memory".
See also the topic Inserting a memory card in the CPU (Page 139) for a description of how
this property affects the insertion of a memory card into the CPU.
S7-1200 Programmable controller
212
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.6 Protection
7.6.3
Know-how protection
Know-how protection allows you to prevent one or more code blocks (OB, FB, FC, or DB) in
your program from unauthorized access. You create a password to limit access to the code
block. The password-protection prevents unauthorized reading or modification of the code
block. Without the password, you can read only the following information about the code
block:
● Block title, block comment, and block properties
● Transfer parameters (IN, OUT, IN_OUT, Return)
● Call structure of the program
● Global tags in the cross references (without information on the point of use), but local
tags are hidden
When you configure a block for "know-how" protection, the code within the block cannot be
accessed except after entering the password.
Use the "Properties" task card of the code block to configure the know-how protection for
that block. After opening the code block, select "Protection" from Properties.
1. In the Properties for the code block, click
the "Protection" button to display the
"Know-how protection" dialog.
2. Click the "Define" button to enter the
password.
After entering and confirming the password,
click "OK".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
213
Programming concepts
7.6 Protection
7.6.4
Copy protection
An additional security feature allows you to bind program blocks for use with a specific
memory card or CPU. This feature is especially useful for protecting your intellectual
property. When you bind a program block to a specific device, you restrict the program or
code block for use only with a specific memory card or CPU. This feature allows you to
distribute a program or code block electronically (such as over the Internet or through email)
or by sending a memory card. Copy protection is available for OBs (Page 188), FBs
(Page 190), and FCs (Page 190). The S7-1200 CPU supports three types of block
protection:
● Binding to the serial number of a CPU
● Binding to the serial number of a memory card
● Dynamic binding with mandatory password
Use the "Properties" task card of the code block to bind the block to a specific CPU or
memory card.
1. After opening the code block, select "Protection".
2. From the drop-down list under "Copy protection" task, select the type of copy protection
that you want to use.
S7-1200 Programmable controller
214
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.6 Protection
3. For binding to the serial number of a CPU or memory card, select either to insert the
serial number when downloading, or enter the serial number for the memory card or
CPU.
Note
The serial number is case-sensitive.
For dynamic binding with mandatory password, define the password that you must use to
download or copy the block.
When you subsequently download (Page 216) a block with dynamic binding, you must
enter the password to be able to download the block. Note that the copy protection
password and the know-how protection (Page 213) password are two separate
passwords.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
215
Programming concepts
7.7 Downloading the elements of your program
7.7
Downloading the elements of your program
You can download the elements of your project from the programming device to the CPU.
When you download a project, the CPU stores the user program (OBs, FCs, FBs and DBs)
in internal load memory or if a SIMATIC memory card is present in external load memory
(the card).
You can download your project from the programming device to your CPU from any of the
following locations:
● Project tree: Right-click the program element, and then click the context-sensitive
"Download" selection.
● Online menu: Click the "Download to device" selection.
● Toolbar: Click the "Download to device" icon.
● Device configuration: Right-click the CPU and select the elements to download.
Note that if you have applied dynamic binding with mandatory password (Page 214) to any
of the program blocks, you must enter the password for the protected blocks in order to
download them. If you have configured this type of copy protection for multiple blocks, you
must enter the password for each of the protected blocks in order to download them.
Note
Downloading a program does not clear or make any changes to existing values in retentive
memory. If you want to clear retentive memory before a download, then reset your CPU to
factory settings prior to downloading the program.
You can also download a panel project for the Basic HMI panels (Page 32) from the
TIA Portal to a memory card in the S7-1200 CPU.
S7-1200 Programmable controller
216
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.7 Downloading the elements of your program
Downloading when the configured CPU is different from the connected CPU
STEP 7 and the S7-1200 permit a download if the connected CPU has the capacity to store
a download from the configured CPU, based on the memory requirements of the project and
the compatibility of the I/O. You can download the configuration and program from a CPU to
a larger CPU, for example, from a CPU 1211C DC/DC/DC to a CPU 1215C DC/DC/DC
because the I/O is compatible and the memory is sufficient. In this case, the download
operation displays a warning, "Differences between configured and target modules (online)"
along with the article numbers and firmware versions in the "Load preview" dialog. You must
choose either "No action" if you do not want the download to proceed or "Accept all" if you
do want the download to proceed:
Note
When you go online (Page 1313) after downloading the configured CPU to a different
connected CPU, you see the project for the configured CPU with online status indicators in
the project tree. In the online and diagnostics view, however, you see the actual connected
CPU module type.
Figure 7-1
Online view when configured CPU is different from connected CPU
You can, of course, change your device (Page 170) in the device configuration so that the
configured CPU is the same module type as the connected CPU. The "Change device"
dialog provides complete compatibility details when you try to change a device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
217
Programming concepts
7.7 Downloading the elements of your program
STEP 7 and the S7-1200 prohibit a download if the connected CPU does not have the
capacity to store a download from the configured CPU; for example, you cannot download
the hardware configuration and program for the following cases:
● CPU 1215C DC/DC/DC to a CPU 1212C DC/DC/DC due to insufficient work memory
● CPU 1211C DC/DC/Relay to a CPU 1211C DC/DC/DC due to I/O differences
● CPU 1217C DC/DC/DC to any CPU 1211C, CPU 1212C, CPU 1214C, or CPU 1215C
due to the 1.5 V DC outputs in the CPU 1217C.
● CPU 1214C V4.2 to CPU 1214C V4.0, due to firmware version incompatibility
The "Load preview" dialog displays an error in such cases:
Recovering from a failed download
If the download fails, the Info tab of the Inspector Window displays the reason. The
diagnostic buffer also provides information. After a failed download, follow these steps to be
able to download successfully:
1. Correct the problem as described in the error message.
2. Reattempt the download.
In rare cases, the download succeeds but a subsequent power cycle of the CPU fails. In this
case you may see an error in the diagnostic buffer such as:
● 16# 02:4175 -- CPU error: Memory card evaluation error: Unknown or incompatible
version of CPU configuration description current card type: No memory card Function
finished/aborted, new startup inhibit set: ..- Memory card missing, wrong type, wrong
content or protected
If this occurs and additional attempts to download fail, you must clear the internal load
memory or external load memory:
1. If using internal load memory, reset the CPU to factory settings.
2. If using a SIMATIC memory card, remove it and delete the contents of the memory card
(Page 145) before reinserting.
3. Download the hardware configuration and software.
S7-1200 Programmable controller
218
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.8 Synchronizing the online CPU and offline project
See also
Synchronizing the online CPU and offline project (Page 219)
7.8
Synchronizing the online CPU and offline project
When you download project blocks to the CPU, the CPU can detect whether blocks or tags
have changed in the online CPU since the last download. In such cases, the CPU offers you
the choice to synchronize the changes. This means that you can upload the online CPU
changes to the project before downloading the project to the CPU. Changes in the online
CPU can be due to a variety of factors:
● Changes to the start values of data block tags during runtime, for example by the
WRIT_DBL instruction (Page 538) or by loading a recipe
● A download from a "secondary" project (a project other than the one that originated the
last download) where one or more of the following conditions exist:
– The online CPU includes program blocks that do not exist in the project.
– Data block tags or block attributes differ between the offline project and online CPU.
– PLC tags exist in the online CPU that do not exist in the offline project.
Note
If you edit blocks or tags in the project that you used for the last download, you do not have
to make any choices about synchronization. STEP 7 and the CPU detect that the offline
project changes are newer than the online CPU and proceeds with a normal download
operation.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
219
Programming concepts
7.8 Synchronizing the online CPU and offline project
Synchronization choices
When you download a project to the CPU, you see the synchronization dialog if STEP 7
detects that data blocks or tags in the online CPU are newer than the project values. For
example, if the STEP 7 program has executed WRIT_DBL and changed a start value for a
tag in Data_block_1, STEP 7 displays the following synchronization dialog when you initiate
a download:
This dialog lists the program blocks where differences exist. From this dialog, you have the
following choices:
● Online/offline comparison: If you click this button, STEP 7 displays the program blocks,
system blocks, technology objects, PLC tags, and PLC data types for the project as
compared to the online CPU (Page 1323). For each object, you can click to see a
detailed analysis of the differences including time stamps. You can use this information to
decide what to do about the differences between the online CPU and the project.
● Synchronize: If you click this button, STEP 7 uploads the data blocks, tags, and other
objects from the online CPU to the project. You can then continue with the program
download, unless program execution has again caused the project to be out of sync with
the CPU.
● Continue without synchronization: If you click this button, STEP 7 downloads the project
to the CPU.
● Cancel: If you click this button, you cancel the download operation.
S7-1200 Programmable controller
220
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.9 Uploading from the online CPU
7.9
Uploading from the online CPU
You can also copy the program blocks from an online CPU or a memory card attached to
your programming device.
Prepare the offline project for the copied program blocks:
1. Add a CPU device that matches the online CPU.
2. Expand the CPU node once so that the "Program
blocks" folder is visible.
To upload the program blocks from the online CPU to the
offline project, follow these steps:
1. Click the "Program blocks" folder in the offline project.
2. Click the "Go online" button.
3. Click the "Upload" button.
4. Confirm your decision from the Upload dialog
(Page 1313).
When the upload is complete, STEP 7 displays all of the
uploaded program blocks in the project.
7.9.1
Comparing the online CPU to the offline CPU
You can use the "Compare" editor (Page 1323) in STEP 7 to find differences between the
online and offline projects. You might find this useful prior to uploading from the CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
221
Programming concepts
7.10 Debugging and testing the program
7.10
Debugging and testing the program
7.10.1
Monitor and modify data in the CPU
As shown in the following table, you can monitor and modify values in the online CPU.
Table 7- 5
Monitoring and modifying data with STEP 7
Editor
Monitor
Modify
Force
Watch table
Yes
Yes
No
Force table
Yes
No
Yes
Program editor
Yes
Yes
No
Tag table
Yes
No
No
DB editor
Yes
No
No
Monitoring with a
watch table
Monitoring with the LAD editor
Refer to the "Online and diagnostics" chapter for more information about monitoring and
modifying data in the CPU (Page 1325).
S7-1200 Programmable controller
222
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.10 Debugging and testing the program
7.10.2
Watch tables and force tables
You use "watch tables" for monitoring and modifying the values of a user program being
executed by the online CPU. You can create and save different watch tables in your project
to support a variety of test environments. This allows you to reproduce tests during
commissioning or for service and maintenance purposes.
With a watch table, you can monitor and interact with the CPU as it executes the user
program. You can display or change values not only for the tags of the code blocks and data
blocks, but also for the memory areas of the CPU, including the inputs and outputs (I and Q),
peripheral inputs (I:P), bit memory (M), and data blocks (DB).
With the watch table, you can enable the physical outputs (Q:P) of a CPU in STOP mode.
For example, you can assign specific values to the outputs when testing the wiring for the
CPU.
STEP 7 also provides a force table for "forcing" a tag to a specific value. For more
information about forcing, see the section on forcing values in the CPU (Page 1333) in the
"Online and Diagnostics" chapter.
Note
The force values are stored in the CPU and not in the watch table.
You cannot force an input (or "I" address). However, you can force a peripheral input. To
force a peripheral input, append a ":P" to the address (for example: "On:P").
STEP 7 also provides the capability of tracing and recording program variables based on
trigger conditions (Page 1347).
7.10.3
Cross reference to show usage
The Inspector window displays cross-reference information about how a selected object is
used throughout the complete project, such as the user program, the CPU and any HMI
devices. The "Cross-reference" tab displays the instances where a selected object is being
used and the other objects using it. The Inspector window also includes blocks which are
only available online in the cross-references. To display the cross-references, select the
"Show cross-references" command. (In the Project view, find the cross references in the
"Tools" menu.)
Note
You do not have to close the editor to see the cross-reference information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
223
Programming concepts
7.10 Debugging and testing the program
You can sort the entries in the cross-reference. The cross-reference list provides an
overview of the use of memory addresses and tags within the user program.
● When creating and changing a program, you retain an overview of the operands, tags
and block calls you have used.
● From the cross-references, you can jump directly to the point of use of operands and
tags.
● During a program test or when troubleshooting, you are notified about which memory
location is being processed by which command in which block, which tag is being used in
which screen, and which block is called by which other block.
Table 7- 6
Elements of the cross reference
Column
Description
Object
Name of the object that uses the lower-level objects or that is being used by the
lower-level objects
Number
Number of uses
Point of use
Each location of use, for example, network
Property
Special properties of referenced objects, for example, the tag names in multiinstance declarations
as
Shows additional information about the object, such as whether an instance DB is
used as template or as a multiple instance
Access
Type of access, whether access to the operand is read access (R) and/or write
access (W)
Address
Address of the operand
Type
Information on the type and language used to create the object
Path
Path of object in project tree
Depending on the installed products, the cross-reference table displays additional or different
columns.
S7-1200 Programmable controller
224
System Manual, V4.2, 09/2016, A5E02486680-AK
Programming concepts
7.10 Debugging and testing the program
7.10.4
Call structure to examine the calling hierarchy
The call structure describes the call hierarchy of the block within your user program. It
provides an overview of the blocks used, calls to other blocks, the relationships between
blocks, the data requirements for each block, and the status of the blocks. You can open the
program editor and edit blocks from the call structure.
Displaying the call structure provides you with a list of the blocks used in the user program.
STEP 7 highlights the first level of the call structure and displays any blocks that are not
called by any other block in the program. The first level of the call structure displays the OBs
and any FCs, FBs, and DBs that are not called by an OB. If a code block calls another block,
the called block is shown as an indentation under the calling block. The call structure only
displays those blocks that are called by a code block.
You can selectively display only the blocks causing conflicts within the call structure. The
following conditions cause conflicts:
● Blocks that execute any calls with older or newer code time stamps
● Blocks that call a block with modified interface
● Blocks that use a tag with modified address and/or data type
● Blocks that are called neither directly nor indirectly by an OB
● Blocks that call a non-existent or missing block
You can group several block calls and data blocks as a group. You use a drop-down list to
see the links to the various call locations.
You can also perform a consistency check to show time stamp conflicts. Changing the time
stamp of a block during or after the program is generated can lead to time stamp conflicts,
which in turn cause inconsistencies among the blocks that are calling and being called.
● Most time stamp and interface conflicts can be corrected by recompiling the code blocks.
● If compilation fails to clear up inconsistencies, use the link in the "Details" column to go to
the source of the problem in the program editor. You can then manually eliminate any
inconsistencies.
● Any blocks marked in red must be recompiled.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
225
Programming concepts
7.10 Debugging and testing the program
S7-1200 Programmable controller
226
System Manual, V4.2, 09/2016, A5E02486680-AK
8
Basic instructions
8.1
Bit logic operations
8.1.1
Bit logic instructions
LAD and FBD are very effective for handling Boolean logic. While SCL is especially effective
for complex mathematical computation and for project control structures, you can use SCL
for Boolean logic.
LAD contacts
Table 8- 1
LAD
Table 8- 2
Normally open and normally closed contacts
SCL
IF in THEN
Statement;
ELSE
Statement;
END_IF;
IF NOT (in) THEN
Statement;
ELSE
Statement;
END_IF;
Description
Normally open and normally closed contacts: You can connect contacts
to other contacts and create your own combination logic. If the input bit
you specify uses memory identifier I (input) or Q (output), then the bit
value is read from the process-image register. The physical contact signals in your control process are wired to I terminals on the PLC. The CPU
scans the wired input signals and continuously updates the corresponding state values in the process-image input register.
You can perform an immediate read of a physical input using ":P" following the I offset (example: "%I3.4:P"). For an immediate read, the bit data
values are read directly from the physical input instead of the process
image. An immediate read does not update the process image.
Data types for the parameters
Parameter
Data type
Description
IN
Bool
Assigned bit
● The Normally Open contact is closed (ON) when the assigned bit value is equal to 1.
● The Normally Closed contact is closed (ON) when the assigned bit value is equal to 0.
● Contacts connected in series create AND logic networks.
● Contacts connected in parallel create OR logic networks.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
227
Basic instructions
8.1 Bit logic operations
FBD AND, OR, and XOR boxes
In FBD programming, LAD contact networks are transformed into AND (&), OR (>=1), and
EXCLUSIVE OR (x) box networks where you can specify bit values for the box inputs and
outputs. You may also connect to other logic boxes and create your own logic combinations.
After the box is placed in your network, you can drag the "Insert input" tool from the
"Favorites" toolbar or instruction tree and then drop it onto the input side of the box to add
more inputs. You can also right-click on the box input connector and select "Insert input".
Box inputs and outputs can be connected to another logic box, or you can enter a bit
address or bit symbol name for an unconnected input. When the box instruction is executed,
the current input states are applied to the binary box logic and, if true, the box output will be
true.
Table 8- 3
FBD
1
AND, OR, and XOR boxes
SCL1
out := in1 AND
in2;
Description
out := in1 OR in2;
Any input of an OR box must be TRUE for the output to be
TRUE.
out := in1 XOR
in2;
An odd number of the inputs of an XOR box must be TRUE for
the output to be TRUE.
All inputs of an AND box must be TRUE for the output to be
TRUE.
For SCL: You must assign the result of the operation to a variable to be used for another statement.
Table 8- 4
Data types for the parameters
Parameter
Data type
Description
IN1, IN2
Bool
Input bit
S7-1200 Programmable controller
228
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.1 Bit logic operations
NOT logic inverter
Table 8- 5
LAD
Invert RLO (Result of Logic Operation)
FBD
SCL
NOT
Description
For FBD programming, you can drag the "Invert RLO" tool
from the "Favorites" toolbar or instruction tree and then drop
it on an input or output to create a logic inverter on that box
connector.
The LAD NOT contact inverts the logical state of power flow
input.
•
If there is no power flow into the NOT contact, then there
is power flow out.
•
If there is power flow into the NOT contact, then there is
no power flow out.
Output coil and assignment box
The coil output instruction writes a value for an output bit. If the output bit you specify uses
memory identifier Q, then the CPU turns the output bit in the process-image register on or
off, setting the specified bit equal to power flow status. The output signals for your control
actuators are wired to the Q terminals of the CPU. In RUN mode, the CPU system
continuously scans your input signals, processes the input states according to your program
logic, and then reacts by setting new output state values in the process-image output
register. The CPU system transfers the new output state reaction that is stored in the
process-image register, to the wired output terminals.
Table 8- 6
LAD
Assignment and negate assignment
FBD
SCL
out := ;
out := NOT ;
Description
In FBD programming, LAD coils are transformed into
assignment (= and /=) boxes where you specify a bit address for the box output. Box inputs and outputs can be
connected to other box logic or you can enter a bit address.
You can specify an immediate write of a physical output
using ":P" following the Q offset (example: "%Q3.4:P").
For an immediate write, the bit data values are written to
the process image output and directly to physical output.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
229
Basic instructions
8.1 Bit logic operations
Table 8- 7
Data types for the parameters
Parameter
Data type
Description
OUT
Bool
Assigned bit
● If there is power flow through an output coil or an FBD "=" box is enabled, then the output
bit is set to 1.
● If there is no power flow through an output coil or an FBD "=" assignment box is not
enabled, then the output bit is set to 0.
● If there is power flow through an inverted output coil or an FBD "/=" box is enabled, then
the output bit is set to 0.
● If there is no power flow through an inverted output coil or an FBD "/=" box is not enabled,
then the output bit is set to 1.
8.1.2
Set and reset instructions
Set and Reset 1 bit
Table 8- 8
LAD
S and R instructions
FBD
SCL
Description
Not available
Set output:
When S (Set) is activated, then the data value at the OUT
address is set to 1. When S is not activated, OUT is not
changed.
Not available
Reset output:
When R (Reset) is activated, then the data value at the OUT
address is set to 0. When R is not activated, OUT is not
changed.
1
For LAD and FBD: These instructions can be placed anywhere in the network.
2
For SCL: You must write code to replicate this function within your application.
Table 8- 9
Data types for the parameters
Parameter
Data type
Description
IN (or connect to contact/gate logic)
Bool
Bit tag of location to be monitored
OUT
Bool
Bit tag of location to be set or reset
S7-1200 Programmable controller
230
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.1 Bit logic operations
Set and Reset Bit Field
Table 8- 10
LAD1
SET_BF and RESET_BF instructions
FBD
SCL
Description
Not available
Set bit field:
When SET_BF is activated, a data value of 1 is assigned to "n"
bits starting at address tag OUT. When SET_BF is not activated, OUT is not changed.
Not available
Reset bit field:
RESET_BF writes a data value of 0 to "n" bits starting at address tag OUT. When RESET_BF is not activated, OUT is not
changed.
1
For LAD and FBD: These instructions must be the right-most instruction in a branch.
2
For SCL: You must write code to replicate this function within your application.
Table 8- 11
Data types for the parameters
Parameter
Data type
Description
OUT
Bool
Starting element of a bit field to be set or reset (Example:
#MyArray[3])
n
Constant (UInt)
Number of bits to write
Set-dominant and Reset-dominant flip-flops
Table 8- 12
LAD / FBD
RS and SR instructions
SCL
Description
Not available
Reset/set flip-flop:
RS is a set dominant latch where the set dominates. If the set (S1) and reset (R)
signals are both true, the value at address INOUT will be 1.
Not available
Set/reset flip-flop:
SR is a reset dominant latch where the reset dominates. If the set (S) and reset
(R1) signals are both true, the value at address INOUT will be 0.
1
For LAD and FBD: These instructions must be the right-most instruction in a branch.
2
For SCL: You must write code to replicate this function within your application.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
231
Basic instructions
8.1 Bit logic operations
Table 8- 13
Data types for the parameters
Parameter
Data type
Description
S, S1
Bool
Set input; 1 indicates dominance
R, R1
Bool
Reset input; 1 indicates dominance
INOUT
Bool
Assigned bit tag "INOUT"
Q
Bool
Follows state of "INOUT" bit
The "INOUT" tag assigns the bit address that is set or reset. The optional output Q follows
the signal state of the "INOUT" address.
Instruction
RS
SR
S1
R
"INOUT" bit
0
0
Previous state
0
1
0
1
0
1
1
1
1
S
R1
0
0
Previous state
0
1
0
1
0
1
1
1
0
S7-1200 Programmable controller
232
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.1 Bit logic operations
8.1.3
Table 8- 14
LAD
Positive and negative edge instructions
Positive and negative transition detection
FBD
SCL
Not available
Description
1
Scan operand for positive signal edge.
LAD: The state of this contact is TRUE when a positive transition (OFFto-ON) is detected on the assigned "IN" bit. The contact logic state is
then combined with the power flow in state to set the power flow out
state. The P contact can be located anywhere in the network except the
end of a branch.
FBD: The output logic state is TRUE when a positive transition (OFFto-ON) is detected on the assigned input bit. The P box can only be
located at the beginning of a branch.
Not available 1
Scan operand for negative signal edge.
LAD: The state of this contact is TRUE when a negative transition (ONto-OFF) is detected on the assigned input bit. The contact logic state is
then combined with the power flow in state to set the power flow out
state. The N contact can be located anywhere in the network except
the end of a branch.
FBD: The output logic state is TRUE when a negative transition (ON-toOFF) is detected on the assigned input bit. The N box can only be
located at the beginning of a branch.
Not available 1
Set operand on positve signal edge.
LAD: The assigned bit "OUT" is TRUE when a positive transition (OFFto-ON) is detected on the power flow entering the coil. The power flow
in state always passes through the coil as the power flow out state. The
P coil can be located anywhere in the network.
FBD: The assigned bit "OUT" is TRUE when a positive transition (OFFto-ON) is detected on the logic state at the box input connection or on
the input bit assignment if the box is located at the start of a branch.
The input logic state always passes through the box as the output logic
state. The P= box can be located anywhere in the branch.
Not available 1
Set operand on negative signal edge.
LAD: The assigned bit "OUT" is TRUE when a negative transition (ONto-OFF) is detected on the power flow entering the coil. The power flow
in state always passes through the coil as the power flow out state. The
N coil can be located anywhere in the network.
FBD: The assigned bit "OUT" is TRUE when a negative transition (ONto-OFF) is detected on the logic state at the box input connection or on
the input bit assignment if the box is located at the start of a branch.
The input logic state always passes through the box as the output logic
state. The N= box can be located anywhere in the branch.
1
For SCL: You must write code to replicate this function within your application.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
233
Basic instructions
8.1 Bit logic operations
Table 8- 15
LAD / FBD
P_TRIG and N_TRIG
SCL
Not available
Description
1
Scan RLO (result of logic operation) for positve signal edge.
The Q output power flow or logic state is TRUE when a positive transition (OFF-to-ON) is detected on the CLK input state (FBD) or CLK power flow in (LAD).
In LAD, the P_TRIG instruction cannot be located at the beginning or
end of a network. In FBD, the P_TRIG instruction can be located anywhere except the end of a branch.
Not available 1
Scan RLO for negative signal edge.
The Q output power flow or logic state is TRUE when a negative transition (ON-to-OFF) is detected on the CLK input state (FBD) or CLK power flow in (LAD).
In LAD, the N_TRIG instruction cannot be located at the beginning or
end of a network. In FBD, the N_TRIG instruction can be located anywhere except the end of a branch.
1
For SCL: You must write code to replicate this function within your application.
Table 8- 16
LAD / FBD
R_TRIG and F_TRIG instructions
SCL
"R_TRIG_DB"(
CLK:=_in_,
Q=> _bool_out_);
Description
Set tag on positive signal edge.
The assigned instance DB is used to store the previous state of the CLK
input. The Q output power flow or logic state is TRUE when a positive
transition (OFF-to-ON) is detected on the CLK input state (FBD) or CLK
power flow in (LAD).
In LAD, the R_TRIG instruction cannot be located at the beginning or
end of a network. In FBD, the R_TRIG instruction can be located anywhere except the end of a branch.
"F_TRIG_DB"(
CLK:=_in_,
Q=> _bool_out_);
Set tag on negative signal edge.
The assigned instance DB is used to store the previous state of the CLK
input. The Q output power flow or logic state is TRUE when a negative
transition (ON-to-OFF) is detected on the CLK input state (FBD) or CLK
power flow in (LAD).
In LAD, the F_TRIG instruction cannot be located at the beginning or
end of a network. In FBD, the F_TRIG instruction can be located anywhere except the end of a branch.
S7-1200 Programmable controller
234
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.1 Bit logic operations
For R_TRIG and F_TRIG, when you insert the instruction in the program, the "Call options"
dialog opens automatically. In this dialog you can assign
whether the edge memory bit is stored in its own data block (single instance) or as a local
tag (multiple instance) in the
block interface. If you create a separate data block, you will find it in the project tree in the
"Program resources" folder
under "Program blocks > System blocks".
Table 8- 17
Data types for the parameters (P and N contacts/coils, P=, N=, P_TRIG and N_TRIG)
Parameter
Data type
Description
M_BIT
Bool
Memory bit in which the previous state of the input is saved
IN
Bool
Input bit whose transition edge is detected
OUT
Bool
Output bit which indicates a transition edge was detected
CLK
Bool
Power flow or input bit whose transition edge is detected
Q
Bool
Output which indicates an edge was detected
All edge instructions use a memory bit (M_BIT: P/N contacts/coils, P_TRIG/N_TRIG) or
(instance DB bit: R_TRIG, F_TRIG) to store the previous state of the monitored input signal.
An edge is detected by comparing the state of the input with the previous state. If the states
indicate a change of the input in the direction of interest, then an edge is reported by writing
the output TRUE. Otherwise, the output is written to FALSE.
Note
Edge instructions evaluate the input and memory-bit values each time they are executed,
including the first execution. You must account for the initial states of the input and memory
bit in your program design either to allow or to avoid edge detection on the first scan.
Because the memory bit must be maintained from one execution to the next, you should use
a unique bit for each edge instruction, and you should not use this bit any other place in your
program. You should also avoid temporary memory and memory that can be affected by
other system functions, such as an I/O update. Use only M, global DB, or Static memory (in
an instance DB) for M_BIT memory assignments.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
235
Basic instructions
8.2 Timer operations
8.2
Timer operations
You use the timer instructions to create programmed time delays. The number of timers that
you can use in your user program is limited only by the amount of memory in the CPU. Each
timer uses a 16 byte IEC_Timer data type DB structure to store timer data that is specified at
the top of the box or coil instruction. STEP 7 automatically creates the DB when you insert
the instruction.
Table 8- 18
Timer instructions
LAD / FBD boxes
FBD only:
LAD coils
SCL
"IEC_Timer_0_DB".TP(
IN:=_bool_in_,
PT:=_time_in_,
Q=>_bool_out_,
ET=>_time_out_);
Description
The TP timer generates a pulse with a preset
width time.
"IEC_Timer_0_DB".TON (
IN:=_bool_in_,
PT:=_time_in_,
Q=>_bool_out_,
ET=>_time_out_);
The TON timer sets output Q to ON after a preset
time delay.
"IEC_Timer_0_DB".TOF (
IN:=_bool_in_,
PT:=_time_in_,
Q=>_bool_out_,
ET=>_time_out_);
The TOF timer resets output Q to OFF after a
preset time delay.
"IEC_Timer_0_DB".TONR (
IN:=_bool_in_,
R:=_bool_in_,
PT:=_time_in_,
Q=>_bool_out_,
ET=>_time_out_);
The TONR timer sets output Q to ON after a preset time delay. Elapsed time is accumulated over
multiple timing periods until the R input is used to
reset the elapsed time.
PRESET_TIMER(
PT:=_time_in_,
The PT (Preset timer) coil loads a new PRESET
time value in the specified IEC_Timer.
TIMER:=_iec_timer_in_);
FBD only:
RESET_TIMER(
_iec_timer_in_);
The RT (Reset timer) coil resets the specified
IEC_Timer.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL examples, "IEC_Timer_0_DB" is the name of the instance DB.
S7-1200 Programmable controller
236
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.2 Timer operations
Table 8- 19
Data types for the parameters
Parameter
Data type
Description
Box: IN
Coil: Power flow
Bool
TP, TON, and TONR:
Box: 0=Disable timer, 1=Enable timer
Coil: No power flow=Disable timer, Power flow=Enable timer
TOF:
Box: 0=Enable timer, 1=Disable timer
Coil: No power flow=Enable timer, Power flow=Disable timer
R
Bool
TONR box only:
0=No reset
1= Reset elapsed time and Q bit to 0
Box: PT
Coil: "PRESET_Tag"
Time
Timer box or coil: Preset time input
Box: Q
Coil: DBdata.Q
Bool
Timer box: Q box output or Q bit in the timer DB data
Timer coil: you can only address the Q bit in the timer DB data
Box: ET
Coil: DBdata.ET
Time
Timer box: ET (elapsed time) box output or ET time value in the timer DB
data
Timer coil: you can only address the ET time value in the timer DB data.
Table 8- 20
Effect of value changes in the PT and IN parameters
Timer
Changes in the PT and IN box parameters and the corresponding coil parameters
TP
•
Changing PT has no effect while the timer runs.
•
Changing IN has no effect while the timer runs.
•
Changing PT has no effect while the timer runs.
•
Changing IN to FALSE, while the timer runs, resets and stops the timer.
•
Changing PT has no effect while the timer runs.
•
Changing IN to TRUE, while the timer runs, resets and stops the timer.
•
Changing PT has no effect while the timer runs, but has an effect when the timer resumes.
•
Changing IN to FALSE, while the timer runs, stops the timer but does not reset the timer. Changing
IN back to TRUE will cause the timer to start timing from the accumulated time value.
TON
TOF
TONR
PT (preset time) and ET (elapsed time) values are stored in the specified IEC_TIMER DB
data as signed double integers that represent milliseconds of time. TIME data uses the T#
identifier and can be entered as a simple time unit (T#200ms or 200) and as compound time
units like T#2s_200ms.
Table 8- 21
Data type
TIME
1
Size and range of the TIME data type
Size
32 bits, stored
as DInt data
Valid number ranges1
T#-24d_20h_31m_23s_648ms to T#24d_20h_31m_23s_647ms
Stored as -2,147,483,648 ms to +2,147,483,647 ms
The negative range of the TIME data type shown above cannot be used with the timer instructions. Negative PT (preset
time) values are set to zero when the timer instruction is executed. ET (elapsed time) is always a positive value.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
237
Basic instructions
8.2 Timer operations
Timer coil example
The -(TP)-, -(TON)-, -(TOF)-, and -(TONR)- timer coils must be the last instruction in a LAD
network. As shown in the timer example, a contact instruction in a subsequent network
evaluates the Q bit in a timer coil's IEC_Timer DB data. Likewise, you must address the
ELAPSED element in the IEC_timer DB data if you want to use the elapsed time value in
your program.
The pulse timer is started on a 0 to 1 transition of the Tag_Input bit value. The timer runs for
the time specified by Tag_Time time value.
As long as the timer runs, the state of DB1.MyIEC_Timer.Q=1 and the Tag_Output value=1.
When the Tag_Time value has elapsed, then DB1.MyIEC_Timer.Q=0 and the Tag_Output
value=0.
Reset timer -(RT)- and Preset timer -(PT)- coils
These coil instructions can be used with box or coil timers and can be placed in a mid-line
position. The coil output power flow status is always the same as the coil input status. When
the -(RT)- coil is activated, the ELAPSED time element of the specified IEC_Timer DB data
is reset to 0. When the -(PT)- coil is activated, the PRESET time element of the specified
IEC_Timer DB data is loaded with the assigned time-duration value..
Note
When you place timer instructions in an FB, you can select the "Multi-instance data block"
option. The timer structure names can be different with separate data structures, but the
timer data is contained in a single data block and does not require a separate data block for
each timer. This reduces the processing time and data storage necessary for handling the
timers. There is no interaction between the timer data structures in the shared multi-instance
DB.
S7-1200 Programmable controller
238
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.2 Timer operations
Operation of the timers
Table 8- 22
Types of IEC timers
Timer
Timing diagram
TP: Generate pulse
The TP timer generates a pulse with a preset width
time.
TON: Generate ON-delay
The TON timer sets output Q to ON after a preset time
delay.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
239
Basic instructions
8.2 Timer operations
Timer
Timing diagram
TOF: Generate OFF-delay
The TOF timer resets output Q to OFF after a preset
time delay.
TONR: Time accumulator
The TONR timer sets output Q to ON after a preset time
delay. Elapsed time is accumulated over multiple timing
periods until the R input is used to reset the elapsed
time.
Note
In the CPU, no dedicated resource is allocated to any specific timer instruction. Instead,
each timer utilizes its own timer structure in DB memory and a continuously-running internal
CPU timer to perform timing.
When a timer is started due to an edge change on the input of a TP, TON, TOF, or TONR
instruction, the value of the continuously-running internal CPU timer is copied into the
START member of the DB structure allocated for this timer instruction. This start value
remains unchanged while the timer continues to run, and is used later each time the timer is
updated. Each time the timer is started, a new start value is loaded into the timer structure
from the internal CPU timer.
When a timer is updated, the start value described above is subtracted from the current
value of the internal CPU timer to determine the elapsed time. The elapsed time is then
compared with the preset to determine the state of the timer Q bit. The ELAPSED and Q
members are then updated in the DB structure allocated for this timer. Note that the elapsed
time is clamped at the preset value (the timer does not continue to accumulate elapsed time
after the preset is reached).
S7-1200 Programmable controller
240
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.2 Timer operations
A timer update is performed when and only when:
● A timer instruction (TP, TON, TOF, or TONR) is executed
● The "ELAPSED" member of the timer structure in DB is referenced directly by an
instruction
● The "Q" member of the timer structure in DB is referenced directly by an instruction
Timer programming
The following consequences of timer operation should be considered when planning and
creating your user program:
● You can have multiple updates of a timer in the same scan. The timer is updated each
time the timer instruction (TP, TON, TOF, TONR) is executed and each time the
ELAPSED or Q member of the timer structure is used as a parameter of another
executed instruction. This is an advantage if you want the latest time data (essentially an
immediate read of the timer). However, if you desire to have consistent values throughout
a program scan, then place your timer instruction prior to all other instructions that need
these values, and use tags from the Q and ET outputs of the timer instruction instead of
the ELAPSED and Q members of the timer DB structure.
● You can have scans during which no update of a timer occurs. It is possible to start your
timer in a function, and then cease to call that function again for one or more scans. If no
other instructions are executed which reference the ELAPSED or Q members of the timer
structure, then the timer will not be updated. A new update will not occur until either the
timer instruction is executed again or some other instruction is executed using ELAPSED
or Q from the timer structure as a parameter.
● Although not typical, you can assign the same DB timer structure to multiple timer
instructions. In general, to avoid unexpected interaction, you should only use one timer
instruction (TP, TON, TOF, TONR) per DB timer structure.
● Self-resetting timers are useful to trigger actions that need to occur periodically. Typically,
self-resetting timers are created by placing a normally-closed contact which references
the timer bit in front of the timer instruction. This timer network is typically located above
one or more dependent networks that use the timer bit to trigger actions. When the timer
expires (elapsed time reaches preset value), the timer bit is ON for one scan, allowing the
dependent network logic controlled by the timer bit to execute. Upon the next execution of
the timer network, the normally closed contact is OFF, thus resetting the timer and
clearing the timer bit. The next scan, the normally closed contact is ON, thus restarting
the timer. When creating self-resetting timers such as this, do not use the "Q" member of
the timer DB structure as the parameter for the normally-closed contact in front of the
timer instruction. Instead, use the tag connected to the "Q" output of the timer instruction
for this purpose. The reason to avoid accessing the Q member of the timer DB structure
is because this causes an update to the timer and if the timer is updated due to the
normally closed contact, then the contact will reset the timer instruction immediately. The
Q output of the timer instruction will not be ON for the one scan and the dependent
networks will not execute.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
241
Basic instructions
8.2 Timer operations
Time data retention after a RUN-STOP-RUN transition or a CPU power cycle
If a run mode session is ended with stop mode or a CPU power cycle and a new run mode
session is started, then the timer data stored in the previous run mode session is lost, unless
the timer data structure is specified as retentive (TP, TON, TOF, and TONR timers).
When you accept the defaults in the call options dialog after you place a timer instruction in
the program editor, you are automatically assigned an instance DB which cannot be made
retentive. To make your timer data retentive, you must either use a global DB or a Multiinstance DB.
Assign a global DB to store timer data as retentive data
This option works regardless of where the timer is placed (OB, FC, or FB).
1. Create a global DB:
– Double-click "Add new block" from the Project tree
– Click the data block (DB) icon
– For the Type, choose global DB
– If you want to be able to select individual data elements in this DB as retentive, be
sure the DB type "Optimized" box is checked. The other DB type option "Standard compatible with S7-300/400" only allows setting all DB data elements retentive or
none retentive.
– Click OK
2. Add timer structure(s) to the DB:
– In the new global DB, add a new static tag using data type IEC_Timer.
– In the "Retain" column, check the box so that this structure will be retentive.
– Repeat this process to create structures for all the timers that you want to store in this
DB. You can either place each timer structure in a unique global DB, or you can place
multiple timer structures into the same global DB. You can also place other static tags
besides timers in this global DB. Placing multiple timer structures into the same global
DB allows you to reduce your overall number of blocks.
– Rename the timer structures if desired.
3. Open the program block for editing where you want to place a retentive timer (OB, FC, or
FB).
4. Place the timer instruction at the desired location.
5. When the call options dialog appears, click the cancel button.
6. On the top of the new timer instruction, type the name (do not use the helper to browse)
of the global DB and timer structure that you created above (example:
"Data_block_3.Static_1").
S7-1200 Programmable controller
242
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.2 Timer operations
Assign a multi-instance DB to store timer data as retentive data
This option only works if you place the timer in an FB.
This option depends upon whether the FB properties specify "Optimized block access"
(allows symbolic access only). To verify how the access attribute is configured for an existing
FB, right-click on the FB in the Project tree, choose properties, and then choose Attributes.
If the FB specifies "Optimized block access" (allows symbolic access only):
1. Open the FB for edit.
2. Place the timer instruction at the desired location in the FB.
3. When the Call options dialog appears, click the Multi instance icon. The Multi Instance
option is only available if the instruction is being placed into an FB.
4. In the Call options dialog, rename the timer if desired.
5. Click OK. The timer instruction appears in the editor, and the IEC_TIMER structure
appears in the FB Interface under Static.
6. If necessary, open the FB interface editor (may have to click on the small arrow to expand
the view).
7. Under Static, locate the timer structure that was just created for you.
8. In the Retain column for this timer structure, change the selection to "Retain". Whenever
this FB is called later from another program block, an instance DB will be created with this
interface definition which contains the timer structure marked as retentive.
If the FB does not specify "Optimized block access", then the block access type is standard,
which is compatible with S7-300/400 classic configurations and allows symbolic and direct
access. To assign a multi-instance to a standard block access FB, follow these steps:
1. Open the FB for edit.
2. Place the timer instruction at the desired location in the FB.
3. When the Call options dialog appears, click on the multi instance icon. The multi instance
option is only available if the instruction is being placed into an FB.
4. In the Call options dialog, rename the timer if desired.
5. Click OK. The timer instruction appears in the editor, and the IEC_TIMER structure
appears in the FB Interface under Static.
6. Open the block that will use this FB.
7. Place this FB at the desired location. Doing so results in the creation of an instance data
block for this FB.
8. Open the instance data block created when you placed the FB in the editor.
9. Under Static, locate the timer structure of interest. In the Retain column for this timer
structure, check the box to make this structure retentive.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
243
Basic instructions
8.3 Counter operations
8.3
Table 8- 23
Counter operations
Counter instructions
LAD / FBD
SCL
"IEC_Counter_0_DB".CTU
(
CU:=_bool_in,
R:=_bool_in,
PV:=_in,
Q=>_bool_out,
CV=>_out);
"IEC_Counter_0_DB".CTD
(
CD:=_bool_in,
LD:=_bool_in,
PV:=_in,
Q=>_bool_out,
CV=>_out);
"IEC_Counter_0_DB".CTU
D(
CU:=_bool_in,
CD:=_bool_in,
R:=_bool_in,
LD:=_bool_in,
PV:=_in_,
QU=>_bool_out,
QD=>_bool_out,
CV=>_out_);
Description
Use the counter instructions to count internal program events and
external process events. Each counter uses a structure stored in a
data block to maintain counter data. You assign the data block when
the counter instruction is placed in the editor.
•
CTU is a count-up counter
•
CTD is a count-down counter
•
CTUD is a count-up-and-down counter
1
For LAD and FBD: Select the count value data type from the drop-down list below the instruction name.
2
STEP 7 automatically creates the DB when you insert the instruction.
3
In the SCL examples, "IEC_Counter_0_DB" is the name of the instance DB.
Table 8- 24
1
Data types for the parameters
Parameter
Data type1
Description
CU, CD
Bool
Count up or count down, by one count
R (CTU, CTUD)
Bool
Reset count value to zero
LD (CTD, CTUD)
Bool
Load control for preset value
PV
SInt, Int, DInt, USInt, UInt, UDInt
Preset count value
Q, QU
Bool
True if CV >= PV
QD
Bool
True if CV <= 0
CV
SInt, Int, DInt, USInt, UInt, UDInt
Current count value
The numerical range of count values depends on the data type you select. If the count value is an unsigned integer
type, you can count down to zero or count up to the range limit. If the count value is a signed integer, you can count
down to the negative integer limit and count up to the positive integer limit.
S7-1200 Programmable controller
244
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.3 Counter operations
The number of counters that you can use in your user program is limited only by the amount
of memory in the CPU. Counters use the following amount of memory:
● For SInt or USInt data types, the counter instruction uses 3 bytes.
● For Int or UInt data types, the counter instruction uses 6 bytes.
● For DInt or UDInt data types, the counter instruction uses 12 bytes.
These instructions use software counters whose maximum counting rate is limited by the
execution rate of the OB in which they are placed. The OB that the instructions are placed in
must be executed often enough to detect all transitions of the CU or CD inputs. For faster
counting operations, see the CTRL_HSC instruction (Page 555).
Note
When you place counter instructions in an FB, you can select the multi-instance DB option,
the counter structure names can be different with separate data structures, but the counter
data is contained in a single DB and does not require a separate DB for each counter. This
reduces the processing time and data storage necessary for the counters. There is no
interaction between the counter data structures in the shared multi-instance DB.
Operation of the counters
Table 8- 25
Operation of CTU (count up)
Counter
Operation
The CTU counter counts up by 1 when the value of parameter CU
changes from 0 to 1. The CTU timing diagram shows the operation for
an unsigned integer count value (where PV = 3).
•
If the value of parameter CV (current count value) is greater than or
equal to the value of parameter PV (preset count value), then the
counter output parameter Q = 1.
•
If the value of the reset parameter R changes from 0 to 1, then the
current count value is reset to 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
245
Basic instructions
8.3 Counter operations
Table 8- 26
Operation of CTD (count down)
Counter
Operation
The CTD counter counts down by 1 when the value of parameter CD changes from 0 to 1. The CTD timing diagram shows
the operation for an unsigned integer count value (where PV =
3).
•
If the value of parameter CV (current count value) is equal
to or less than 0, the counter output parameter Q = 1.
•
If the value of parameter LOAD changes from 0 to 1, the
value at parameter PV (preset value) is loaded to the counter as the new CV (current count value).
Table 8- 27
Operation of CTUD (count up and down)
Counter
Operation
The CTUD counter counts up or
down by 1 on the 0 to 1 transition of the count up (CU) or
count down (CD) inputs. The
CTUD timing diagram shows the
operation for an unsigned integer count value (where PV = 4).
•
If the value of parameter CV
is equal to or greater than the
value of parameter PV, then
the counter output parameter
QU = 1.
•
If the value of parameter CV
is less than or equal to zero,
then the counter output parameter QD = 1.
•
If the value of parameter
LOAD changes from 0 to 1,
then the value at parameter
PV is loaded to the counter
as the new CV.
•
If the value of the reset parameter R is changes from 0
to 1, the current count value
is reset to 0.
S7-1200 Programmable controller
246
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.3 Counter operations
Counter data retention after a RUN-STOP-RUN transition or a CPU power cycle
If a run mode session is ended with stop mode or a CPU power cycle and a new run mode
session is started, then the counter data stored in the previous run mode session is lost,
unless the counter data structure is specified as retentive (CTU, CTD, and CTUD counters).
When you accept the defaults in the call options dialog after you place a counter instruction
in the program editor, you are automatically assigned an instance DB which cannot be made
retentive. To make your counter data retentive, you must either use a global DB or a Multiinstance DB.
Assign a global DB to store counter data as retentive data
This option works regardless of where the counter is placed (OB, FC, or FB).
1. Create a global DB:
– Double-click "Add new block" from the Project tree
– Click the data block (DB) icon
– For the Type, choose global DB
– If you want to be able to select individual items in this DB as retentive, be sure the
symbolic-access-only box is checked.
– Click OK
2. Add counter structure(s) to the DB:
– In the new global DB, add a new static tag using one of the counter data types. Be
sure to consider the Type you want to use for your Preset and Count values.
– In the "Retain" column, check the box so that this structure will be retentive.
– Repeat this process to create structures for all the counters that you want to store in
this DB. You can either place each counter structure in a unique global DB, or you can
place multiple counter structures into the same global DB. You can also place other
static tags besides counters in this global DB. Placing multiple counter structures into
the same global DB allows you to reduce your overall number of blocks.
– Rename the counter structures if desired.
3. Open the program block for editing where you want to place a retentive counter (OB, FC,
or FB).
4. Place the counter instruction at the desired location.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
247
Basic instructions
8.3 Counter operations
5. When the call options dialog appears, click the cancel button. You should now see a new
counter instruction which has "???" both just above and just below the instruction name.
6. On the top of the new counter instruction, type the name (do not use the helper to
browse) of the global DB and counter structure that you created above (example:
"Data_block_3.Static_1"). This causes the corresponding preset and count value type to
be filled in (example: UInt for an IEC_UCounter structure).
Counter Data Type
Corresponding Type for the Preset and Count Values
IEC_Counter
INT
IEC_SCounter
SINT
IEC_DCounter
DINT
IEC_UCounter
UINT
IEC_USCounter
USINT
IEC_UDCounter
UDINT
Assign a multi-instance DB to store counter data as retentive data
This option only works if you place the counter in an FB.
This option depends upon whether the FB properties specify "Optimized block access"
(allows symbolic access only). To verify how the access attribute is configured for an existing
FB, right-click on the FB in the Project tree, choose properties, and then choose Attributes.
If the FB specifies "Optimized block access" (allows symbolic access only):
1. Open the FB for edit.
2. Place the counter instruction at the desired location in the FB.
3. When the Call options dialog appears, click on the Multi instance icon. The Multi Instance
option is only available if the instruction is being placed into an FB.
4. In the Call options dialog, rename the counter if desired.
5. Click OK. The counter instruction appears in the editor with type INT for the preset and
count values, and the IEC_COUNTER structure appears in the FB Interface under Static.
6. If desired, change the type in the counter instruction from INT to one of the other types.
The counter structure will change correspondingly.
7. If necessary, open the FB interface editor (may have to click on the small arrow to expand
the view).
8. Under Static, locate the counter structure that was just created for you.
9. In the Retain column for this counter structure, change the selection to "Retain".
Whenever this FB is called later from another program block, an instance DB will be
created with this interface definition which contains the counter structure marked as
retentive.
S7-1200 Programmable controller
248
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.3 Counter operations
If the FB does not specify "Optimized block access", then the block access type is standard,
which is compatible with S7-300/400 classic configurations and allows symbolic and direct
access. To assign a multi-instance to a standard block access FB, follow these steps:
1. Open the FB for edit.
2. Place the counter instruction at the desired location in the FB.
3. When the Call options dialog appears, click on the multi instance icon. The multi instance
option is only available if the instruction is being placed into an FB.
4. In the Call options dialog, rename the counter if desired.
5. Click OK. The counter instruction appears in the editor with type INT for the preset and
count value, and the IEC_COUNTER structure appears in the FB Interface under Static.
6. If desired, change the type in the counter instruction from INT to one of the other types.
The counter structure will change correspondingly.
7. Open the block that will use this FB.
8. Place this FB at the desired location. Doing so results in the creation of an instance data
block for this FB.
9. Open the instance data block created when you placed the FB in the editor.
10.Under Static, locate the counter structure of interest. In the Retain column for this counter
structure, check the box to make this structure retentive.
Type shown in counter instruction (for preset Corresponding structure Type shown in FB
and count values)
interface
INT
IEC_Counter
SINT
IEC_SCounter
DINT
IEC_DCounter
UINT
IEC_UCounter
USINT
IEC_USCounter
UDINT
IEC_UDCounter
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
249
Basic instructions
8.4 Comparator operations
8.4
Comparator operations
8.4.1
Compare values instructions
Table 8- 28
Compare instructions
LAD
1
FBD
SCL
out := in1 = in2;
or
IF in1 = in2
THEN out := 1;
ELSE out := 0;
END_IF;
Description
Compares two values of the same data type. When the
LAD contact comparison is TRUE, then the contact is
activated. When the FBD box comparison is TRUE,
then the box output is TRUE.
For LAD and FBD: Click the instruction name (such as "==") to change the comparison type from the drop-down list.
Click the "???" and select data type from the drop-down list.
Table 8- 29
Data types for the parameters
Parameter
Data type
Description
IN1, IN2
Byte, Word, DWord, SInt, Int, DInt, USInt, UInt, UDInt, Real,
LReal, String, WString, Char, Char, Time, Date, TOD, DTL,
Constant
Values to compare
Table 8- 30
Comparison descriptions
Relation type
The comparison is true if ...
=
IN1 is equal to IN2
<>
IN1 is not equal to IN2
>=
IN1 is greater than or equal to IN2
<=
IN1 is less than or equal to IN2
>
IN1 is greater than IN2
<
IN1 is less than IN2
S7-1200 Programmable controller
250
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.4 Comparator operations
8.4.2
Table 8- 31
IN_Range (Value within range) and OUT_Range (Value outside range)
Value within Range and value outside range instructions
LAD / FBD
SCL
out := IN_RANGE(min,
val, max);
Description
Tests whether an input value is in or out of a specified value range.
If the comparison is TRUE, then the box output is TRUE.
out := OUT_RANGE(min,
val, max);
1
For LAD and FBD: Click the "???" and select the data type from the drop-down list.
Table 8- 32
1
Data types for the parameters
Parameter
Data type1
Description
MIN, VAL, MAX
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal,
Constant
Comparator inputs
The input parameters MIN, VAL, and MAX must be the same data type.
● The IN_RANGE comparison is true if: MIN <= VAL <= MAX
● The OUT_RANGE comparison is true if: VAL < MIN or VAL > MAX
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
251
Basic instructions
8.4 Comparator operations
8.4.3
Table 8- 33
LAD
OK (Check validity) and NOT_OK (Check invalidity)
OK (check validity) and Not OK (check invalidity) instructions
FBD
SCL
Description
Not available
Tests whether an input data reference is a valid real number according to IEEE specification 754.
Not available
For LAD and FBD: When the LAD contact is TRUE, the contact is activated and passes power flow. When the FBD box
is TRUE, then the box output is TRUE.
1
Table 8- 34
Parameter
Data type
Description
IN
Real, LReal
Input data
Table 8- 35
1
Data types for the parameter
Operation
Instruction
The Real number test is TRUE if:
OK
The input value is a valid real number 1
NOT_OK
The input value is not a valid real number 1
A Real or LReal value is invalid if it is +/- INF (infinity), NaN (Not a Number), or if it is a denormalized value. A denormalized value is a number very close to zero. The CPU substitutes a zero for a denormalized value in calculations.
S7-1200 Programmable controller
252
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.4 Comparator operations
8.4.4
Variant and array comparison instructions
8.4.4.1
Equality and non-equality comparison instructions
The S7-1200 CPU provides instructions for querying the data type of a tag to which a Variant
operand points for either equality or non-equality to the data type of the other operand.
In addition, the S7-1200 CPU provides instructions for querying the data type of an array
element for either equality or non-equality to the data type of the other operand.
In these instructions, you are comparing to . must
have the Variant data type. can be an elementary data type of a PLC data type.
In LAD and FBD, is the operand above the instruction. In LAD, is
the operand below the instruction.
For all instructions, the result of logic operation (RLO) is 1 (true) if the equality or nonequality test passes, and is 0 (false) if not.
The equality and non-equality type comparison instructions are as follows:
● EQ_Type (Compare data type for EQUAL with the data type of a tag)
● NE_Type (Compare data type for UNEQUAL with the data type of a tag)
● EQ_ElemType (Compare data type of an ARRAY element for EQUAL with the data type
of a tag)
● NE_ElemType (Compare data type of an ARRAY element for UNEQUAL with the data
type of a tag)
Table 8- 36
LAD
EQ and NE instructions
FBD
SCL
Description
Not available
Tests whether the tag pointed to by the Variant
at Operand1 is of the same data type as the
tag at Operand2.
Not available
Tests whether the tag pointed to by the Variant
at Operand1 is of a different data type as the
tag at Operand2.
Not available
Tests whether the array element pointed to by
the Variant at Operand1 is of the same data
type as the tag at Operand2.
Not available
Tests whether the array element pointed to by
the Variant at Operand1 is of a different data
type as the tag at Operand2.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
253
Basic instructions
8.4 Comparator operations
Table 8- 37
Data types for the parameters
Parameter
Data type
Description
Operand1
Variant
First operand
Operand2
Bit strings, integers, floating-point numbers,
timers, date and time, character strings,
ARRAY, PLC data types
Second operand
8.4.4.2
Null comparsion instructions
You can use the instructions IS_NULL and NOT_NULL to determine whether or not the input
actually points to an object or not.
For both instructions, must have the Variant data type.
Table 8- 38
LAD
Table 8- 39
IS_NULL (Query for EQUALS ZERO pointer) and NOT_NULL (Query for EQUALS ZERO pointer) instructions
FBD
SCL
Description
Not available
Tests whether the tag pointed to by the Variant
at Operand is null and therefore not an object.
Not available
Tests whether the tag pointed to by the Variant
at Operand is not null and therefore does point
to an object.
Data types for the parameters
Parameter
Data type
Description
Operand
Variant
Operand to evaluate for null or not null.
8.4.4.3
IS_ARRAY (Check for ARRAY)
You can use the "Check for ARRAY" instruction to query whether the Variant points to a tag
of the Array data type.
The must have the Variant data type.
The instructions returns 1 (true) if the operand is an array.
Table 8- 40
LAD
IS_ARRAY (Check for ARRAY)
FBD
SCL
Description
IS_ARRAY(_variant_in_)
Tests whether the tag pointed to by the Variant
at Operand is an array.
S7-1200 Programmable controller
254
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.5 Math functions
Table 8- 41
Data types for the parameters
Parameter
Data type
Description
Operand
Variant
Operand to evaluate for whether it is an array.
8.5
Math functions
8.5.1
CALCULATE (Calculate)
Table 8- 42
CALCULATE instruction
LAD / FBD
SCL
Description
Use the standard SCL math
expressions to
create the equation.
The CALCULATE instruction lets you create a math function that operates on inputs (IN1, IN2, .. INn) and produces the result at OUT, according to the equation that you define.
Table 8- 43
1
•
Select a data type first. All inputs and the output must be the same
data type.
•
To add another input, click the icon at the last input.
Data types for the parameters
Parameter
Data type1
IN1, IN2, ..INn
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord
The IN and OUT parameters must be the same data type (with implicit conversions of the input parameters). For example: A SINT value for an input would be converted to an INT or a REAL value if OUT is an INT or REAL
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
255
Basic instructions
8.5 Math functions
Click the calculator icon to open the dialog and define your math function. You enter your
equation as inputs (such as IN1 and IN2) and operations. When you click "OK" to save the
function, the dialog automatically creates the inputs for the CALCULATE instruction.
The dialog shows an example and a list of possible instructions that you can include based
on the data type of the OUT parameter:
Note
You also must create an input for any constants in your function. The constant value would
then be entered in the associated input for the CALCULATE instruction.
By entering constants as inputs, you can copy the CALCULATE instruction to other locations
in your user program without having to change the function. You then can change the values
or tags of the inputs for the instruction without modifying the function.
When CALCULATE is executed and all the individual operations in the calculation complete
successfully, then the ENO = 1. Otherwise, ENO = 0.
For an example of the CALCULATE instruction, see "Creating a complex equation with a
simple instruction (Page 42)".
S7-1200 Programmable controller
256
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.5 Math functions
8.5.2
Table 8- 44
LAD / FBD
1
Add, subtract, multiply and divide instructions
SCL
out
out
out
out
:=
:=
:=
:=
in1
in1
in1
in1
+
*
/
in2;
in2;
in2;
in2;
Description
•
ADD: Addition (IN1 + IN2 = OUT)
•
SUB: Subtraction (IN1 - IN2 = OUT)
•
MUL: Multiplication (IN1 * IN2 = OUT)
• DIV: Division (IN1 / IN2 = OUT)
An Integer division operation truncates the fractional part of the quotient
to produce an integer output.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
Table 8- 45
1
Add, subtract, multiply and divide instructions
Data types for the parameters (LAD and FBD)
Parameter
Data type1
Description
IN1, IN2
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Constant
Math operation inputs
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Math operation output
Parameters IN1, IN2, and OUT must be the same data type.
To add an ADD or MUL input, click the "Create" icon or right-click on an input
stub for one of the existing IN parameters and select the "Insert input" command.
To remove an input, right-click on an input stub for one of the existing IN parameters (when
there are more than the original two inputs) and select the "Delete" command.
When enabled (EN = 1), the math instruction performs the specified operation on the input
values (IN1 and IN2) and stores the result in the memory address specified by the output
parameter (OUT). After the successful completion of the operation, the instruction sets ENO
= 1.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
257
Basic instructions
8.5 Math functions
Table 8- 46
ENO
Description
1
No error
0
The Math operation result value would be outside the valid number range of the data type selected. The
least significant part of the result that fits in the destination size is returned.
0
Division by 0 (IN2 = 0): The result is undefined and zero is returned.
0
Real/LReal: If one of the input values is NaN (not a number) then NaN is returned.
0
ADD Real/LReal: If both IN values are INF with different signs, this is an illegal operation and NaN is returned.
0
SUB Real/LReal: If both IN values are INF with the same sign, this is an illegal operation and NaN is returned.
0
MUL Real/LReal: If one IN value is zero and the other is INF, this is an illegal operation and NaN is returned.
0
DIV Real/LReal: If both IN values are zero or INF, this is an illegal operation and NaN is returned.
8.5.3
MOD (return remainder of division)
Table 8- 47
LAD / FBD
1
Modulo (return remainder of division) instruction
SCL
out := in1 MOD in2;
Description
You can use the MOD instruction to return the remainder of an integer
division operation. The value at the IN1 input is divided by the value at
the IN2 input and the remainder is returned at the OUT output.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
Table 8- 48
1
ENO status
Data types for parameters
Parameter
Data type1
Description
IN1 and IN2
SInt, Int, DInt, USInt, UInt, UDInt, Constant
Modulo inputs
OUT
SInt, Int, DInt, USInt, UInt, UDInt
Modulo output
The IN1, IN2, and OUT parameters must be the same data type.
Table 8- 49
ENO
ENO values
Description
1
No error
0
Value IN2 = 0, OUT is assigned the value zero
S7-1200 Programmable controller
258
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.5 Math functions
8.5.4
Table 8- 50
LAD / FBD
NEG (Create twos complement)
NEG (create twos complement) instruction
SCL
-(in);
Description
The NEG instruction inverts the arithmetic sign of the value at parameter IN and stores
the result in parameter OUT.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 51
Data types for parameters
Parameter
Data type1
Description
IN
SInt, Int, DInt, Real, LReal, Constant
Math operation input
OUT
SInt, Int, DInt, Real, LReal
Math operation output
The IN and OUT parameters must be the same data type.
1
Table 8- 52
ENO status
ENO
Description
1
No error
0
The resulting value is outside the valid number range of the selected data type.
Example for SInt: NEG (-128) results in +128 which exceeds the data type maximum.
8.5.5
Table 8- 53
LAD / FBD
1
INC (Increment) and DEC (Decrement)
INC and DEC instructions
SCL
in_out := in_out + 1;
Description
in_out := in_out - 1;
Decrements a signed or unsigned integer number value:
Increments a signed or unsigned integer number value:
IN_OUT value +1 = IN_OUT value
IN_OUT value - 1 = IN_OUT value
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
259
Basic instructions
8.5 Math functions
Table 8- 54
Data types for parameters
Parameter
Data type
Description
IN/OUT
SInt, Int, DInt, USInt, UInt, UDInt
Math operation input and output
Table 8- 55
ENO status
ENO
Description
1
No error
0
The resulting value is outside the valid number range of the selected data type.
Example for SInt: INC (+127) results in +128, which exceeds the data type maximum.
8.5.6
Table 8- 56
LAD / FBD
ABS (Form absolute value)
ABS (absolute value) instruction
SCL
out := ABS(in);
Description
Calculates the absolute value of a signed integer or real number at parameter
IN and stores the result in parameter OUT.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 57
Data types for parameters
Parameter
Data type1
Description
IN
SInt, Int, DInt, Real, LReal
Math operation input
OUT
SInt, Int, DInt, Real, LReal
Math operation output
The IN and OUT parameters must be the same data type.
1
Table 8- 58
ENO status
ENO
Description
1
No error
0
The math operation result value is outside the valid number range of the selected data type.
Example for SInt: ABS (-128) results in +128 which exceeds the data type maximum.
S7-1200 Programmable controller
260
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.5 Math functions
8.5.7
Table 8- 59
MIN (Get minimum) and MAX (Get maximum)
MIN (get minimum) and MAX (get maximum) instructions
LAD / FBD
SCL
out:= MIN(
in1:=_variant_in_,
in2:=_variant_in_
[,...in32]);
out:= MAX(
in1:=_variant_in_,
in2:=_variant_in_
[,...in32]);
Description
The MIN instruction compares the value of two parameters IN1
and IN2 and assigns the minimum (lesser) value to parameter
OUT.
The MAX instruction compares the value of two parameters IN1
and IN2 and assigns the maximum (greater) value to parameter
OUT.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 60
Data types for the parameters
Parameter
Data type1
Description
IN1, IN2
[...IN32]
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Time,
Date, TOD, Constant
Math operation inputs (up to 32 inputs)
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Time,
Date, TOD
Math operation output
The IN1, IN2, and OUT parameters must be the same data type.
1
To add an input, click the "Create" icon or right-click on an input stub for one of
the existing IN parameters and select the "Insert input" command.
To remove an input, right-click on an input stub for one of the existing IN parameters (when
there are more than the original two inputs) and select the "Delete" command.
Table 8- 61
ENO status
ENO
Description
1
No error
0
For Real data type only:
•
At least one input is not a real number (NaN).
•
The resulting OUT is +/- INF (infinity).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
261
Basic instructions
8.5 Math functions
8.5.8
Table 8- 62
LIMIT (Set limit value)
LIMIT (set limit value) instruction
LAD / FBD
SCL
LIMIT(MN:=_variant_in_,
IN:=_variant_in_,
MX:=_variant_in_,
OUT:=_variant_out_);
Description
The Limit instruction tests if the value of parameter IN is inside the
value range specified by parameters MIN and MAX and if not,
clamps the value at MIN or MAX.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 63
Data types for the parameters
Parameter
Data type1
Description
MN, IN, and MX
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Time, Date,
TOD·Constant
Math operation inputs
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Time, Date,
TOD
Math operation output
The MN, IN, MX, and OUT parameters must be the same data type.
1
If the value of parameter IN is within the specified range, then the value of IN is stored in
parameter OUT. If the value of parameter IN is outside of the specified range, then the OUT
value is the value of parameter MIN (if the IN value is less than the MIN value) or the value
of parameter MAX (if the IN value is greater than the MAX value).
Table 8- 64
ENO status
ENO
Description
1
No error
0
Real: If one or more of the values for MIN, IN and MAX is NaN (Not a Number), then NaN is returned.
0
If MIN is greater than MAX, the value IN is assigned to OUT.
SCL examples:
● MyVal := LIMIT(MN:=10,IN:=53, MX:=40); //Result: MyVal = 40
● MyVal := LIMIT(MN:=10,IN:=37, MX:=40); //Result: MyVal = 37
● MyVal := LIMIT(MN:=10,IN:=8, MX:=40); //Result: MyVal = 10
S7-1200 Programmable controller
262
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.5 Math functions
8.5.9
Exponent, logarithm, and trigonometry instructions
You use the floating point instructions to program mathematical operations using a Real or
LReal data type:
● SQR: Form square (IN 2 = OUT)
● SQRT: Form square root (√IN = OUT)
● LN: Form natural logarithm (LN(IN) = OUT)
● EXP: Form exponential value (e IN =OUT), where base e = 2.71828182845904523536
● EXPT: exponentiate (IN1 IN2 = OUT)
EXPT parameters IN1 and OUT are always the same data type, for which you must
select Real or LReal. You can select the data type for the exponent parameter IN2 from
among many data types.
● FRAC: Return fraction (fractional part of floating point number IN = OUT)
● SIN: Form sine value (sin(IN radians) = OUT)
● ASIN: Form arcsine value (arcsine(IN) = OUT radians), where the sin(OUT radians) = IN
● COS: Form cosine (cos(IN radians) = OUT)
● ACOS: Form arccosine value (arccos(IN) = OUT radians), where the cos(OUT radians) =
IN
● TAN: Form tangent value (tan(IN radians) = OUT)
● ATAN: Form arctangent value (arctan(IN) = OUT radians), where the tan(OUT radians) =
IN
Table 8- 65
LAD / FBD
Examples of floating-point math instructions
SCL
out := SQR(in);
or
out := in * in;
out := in1 ** in2;
Description
Square: IN 2 = OUT
For example: If IN = 9, then OUT = 81.
General exponential: IN1 IN2 = OUT
For example: If IN1 = 3 and IN2 = 2, then OUT = 9.
1
For LAD and FBD: Click the "???" (by the instruction name) and select a data type from the drop-down menu.
2
For SCL: You can also use the basic SCL math operators to create the mathematical expressions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
263
Basic instructions
8.5 Math functions
Table 8- 66
Data types for parameters
Parameter
Data type
Description
IN, IN1
Real, LReal, Constant
Inputs
IN2
SInt, Int, DInt, USInt, UInt,UDInt, Real, LReal, Constant
EXPT exponent input
OUT
Real, LReal
Outputs
Table 8- 67
ENO status
ENO
Instruction
Condition
Result (OUT)
1
All
No error
Valid result
0
SQR
Result exceeds valid Real/LReal range
+INF
IN is +/- NaN (not a number)
+NaN
IN is negative
-NaN
IN is +/- INF (infinity) or +/- NaN
+/- INF or +/- NaN
IN is 0.0, negative, -INF, or -NaN
-NaN
IN is +INF or +NaN
+INF or +NaN
Result exceeds valid Real/LReal range
+INF
IN is +/- NaN
+/- NaN
SIN, COS, TAN
IN is +/- INF or +/- NaN
+/- INF or +/- NaN
ASIN, ACOS
IN is outside valid range of -1.0 to +1.0
+NaN
IN is +/- NaN
+/- NaN
ATAN
IN is +/- NaN
+/- NaN
FRAC
IN is +/- INF or +/- NaN
+NaN
EXPT
IN1 is +INF and IN2 is not -INF
+INF
IN1 is negative or -INF
+NaN if IN2 is Real/LReal,
-INF otherwise
IN1 or IN2 is +/- NaN
+NaN
IN1 is 0.0 and IN2 is Real/LReal (only)
+NaN
SQRT
LN
EXP
S7-1200 Programmable controller
264
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6
Move operations
8.6.1
MOVE (Move value), MOVE_BLK (Move block), UMOVE_BLK (Move block
uninterruptible), and MOVE_BLK_VARIANT (Move block)
Use the Move instructions to copy data elements to a new memory address and convert
from one data type to another. The source data is not changed by the move process.
● The MOVE instruction copies a single data element from the source address specified by
the IN parameter to the destination addresses specified by the OUT parameter.
● The MOVE_BLK and UMOVE_BLK instructions have an additional COUNT parameter.
The COUNT specifies how many data elements are copied. The number of bytes per
element copied depends on the data type assigned to the IN and OUT parameter tag
names in the PLC tag table.
Table 8- 68
MOVE, MOVE_BLK, UMOVE_BLK, and MOVE_BLK_VARIANT instructions
LAD / FBD
SCL
out1 := in;
Description
MOVE_BLK(
in:=_variant_in,
count:=_uint_in,
out=>_variant_out);
Interruptible move that copies a block of data
elements to a new address.
UMOVE_BLK(
in:=_variant_in,
count:=_uint_in,
out=>_variant_out);
Uninterruptible move that copies a block of data
elements to a new address.
MOVE_BLK(
SRC:=_variant_in,
COUNT:=_udint_in,
SRC_INDEX:=_dint_in,
Moves the contents of a source memory area to
a destination memory area.
DEST_INDEX:=_dint_in,
DEST=>_variant_out);
1
Copies a data element stored at a specified
address to a new address or multiple addresses.1
You can copy a complete array or elements of
an array to another array of the same data type.
The size (number of elements) of source and
destination array may be different. You can
copy multiple or single elements within an array.
You use Variant data types to point to both the
source and destination arrays.
MOVE instruction: To add another output in LAD or FBD, click the "Create" icon by the output parameter. For SCL, use
multiple assignment statements. You might also use one of the loop constructions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
265
Basic instructions
8.6 Move operations
Table 8- 69
Data types for the MOVE instruction
Parameter
Data type
Description
IN
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Char, WChar, Array, Struct, DTL, Time, Date, TOD,
IEC data types, PLC data types
Source address
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Char, WChar, Array, Struct, DTL, Time, Date, TOD,
IEC data types, PLC data types
Destination address
To add MOVE outputs, click the "Create" icon or right-click on an output stub for
one of the existing OUT parameters and select the "Insert output" command.
To remove an output, right-click on an output stub for one of the existing OUT parameters
(when there are more than the original two outputs) and select the "Delete" command.
Table 8- 70
Data types for the MOVE_BLK and UMOVE_BLK instructions
Parameter
Data type
Description
IN
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal Byte, Word,
DWord, Time, Date, TOD, WChar
Source start address
COUNT
UInt
Number of data elements to copy
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, WChar
Destination start address
Table 8- 71
Data types for the MOVE_BLK_VARIANT instruction
Parameter
Data type
Description
SRC
Variant (which points to an array or individual array element)
Source block from which to copy
COUNT
UDInt
Number of data elements to copy
SRC_INDEX
DInt
Zero-based index into the SRC array
DEST_INDEX
DInt
Zero-based index into the DEST
array
RET_VAL
Int
Error information
DEST
Variant (which points to an array or individualt array element)
Destination area into which to copy
the contents of the source block
S7-1200 Programmable controller
266
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
Note
Rules for data copy operations
• To copy the Bool data type, use SET_BF, RESET_BF, R, S, or output coil (LAD)
(Page 230)
• To copy a single elementary data type, use MOVE
• To copy an array of an elementary data type, use MOVE_BLK or UMOVE_BLK
• To copy a structure, use MOVE
• To copy a string, use S_MOVE (Page 346)
• To copy a single character in a string, use MOVE
• The MOVE_BLK and UMOVE_BLK instructions cannot be used to copy arrays or
structures to the I, Q, or M memory areas.
MOVE_BLK and UMOVE_BLK instructions differ in how interrupts are handled:
● Interrupt events are queued and processed during MOVE_BLK execution. Use the
MOVE_BLK instruction when the data at the move destination address is not used within
an interrupt OB subprogram or, if used, the destination data does not have to be
consistent. If a MOVE_BLK operation is interrupted, then the last data element moved is
complete and consistent at the destination address. The MOVE_BLK operation is
resumed after the interrupt OB execution is complete.
● Interrupt events are queued but not processed until UMOVE_BLK execution is complete.
Use the UMOVE_BLK instruction when the move operation must be completed and the
destination data consistent, before the execution of an interrupt OB subprogram. For
more information, see the section on data consistency (Page 198).
ENO is always true following execution of the MOVE instruction.
Table 8- 72
ENO status
ENO
Condition
Result
1
No error
All COUNT elements were successfully copied.
0
Either the source (IN) range or the destination (OUT)
range exceeds the available memory area.
Elements that fit are copied. No partial elements are copied.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
267
Basic instructions
8.6 Move operations
Table 8- 73
RET_VAL
Condition codes for the MOVE_BLK_VARIANT instruction
Description
(W#16#...)
0000
No error
80B4
Data types do not correspond.
8151
Access to the SRC parameter is not possible.
8152
The operand at the SRC parameter is an invalid type.
8153
Code generation error at the SRC parameter
8154
The operand at the SRC parameter has the data type Bool.
8281
The COUNT parameter has an invalid value.
8382
The value at the SRC_INDEX parameter is outside the limits of the
Variant.
8383
The value at parameter SRC_INDEX is outside the high limit of the
array.
8482
The value at the DEST_INDEX parameter is outside the limits of
the Variant.
8483
The value at parameter DEST_INDEX is outside the high limit of
the array.
8534
The DEST parameter is write-protected.
8551
Access to the DEST parameter is not possible.
8552
The operand at the DEST parameter is an invalid type.
8553
Code generation error at the DEST parameter
8554
The operand at the DEST parameter has the data type Bool.
*You can display error codes in the program editor as integer or hexadecimal values.
S7-1200 Programmable controller
268
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.2
Deserialize
You can use the "Deserialize" instruction to convert the sequential representation of a PLC
data type (UDT) back to a PLC data type and to fill its entire contents. If the comparison is
TRUE, then the box output is TRUE.
The memory area which holds the sequential representation of a PLC data type must have
the Array of Byte data type and you must declare the data block to have standard (not
optimized) access. Make sure that there is enough memory space prior to the conversion.
The instruction enables you to convert multiple sequential representations of converted PLC
data types back to their original data types.
Note
If you only want to convert back a single sequential representation of a PLC data type (UDT),
you can also use the instruction "TRCV: Receive data via communication connection".
Table 8- 74
DESERIALIZE instruction
LAD / FBD
Table 8- 75
SCL
ret_val := Deserialize(
SRC_ARRAY:=_variant_in_,
DEST_VARIABLE=>_variant_out
_,
POS:=_dint_inout_);
Description
Converts the sequential representation of a PLC data type (UDT)
back to a PLC data type and fills
its entire contents
Parameters for the DESERIALIZE instruction
Parameter
Type
Data type
Description
SRC_ARRAY
IN
Variant
Global data block that contains the data stream
DEST_VARIABLE
INOUT
Variant
Tag in which to store the
converted PLC data type
(UDT)
POS
INOUT
DInt
Number of bytes that the
converted PLC data type
uses
RET_VAL
OUT
Int
Error information
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
269
Basic instructions
8.6 Move operations
Table 8- 76
RET_VAL*
(W#16#...)
RET_VAL parameter
Description
0000
No error
80B0
The memory areas for the SRC_ARRAY and DEST_VARIABLE parameters overlap.
8136
The data block at the DEST_VARIABLE parameter is not a block with standard access.
8150
The Variant data type at the SRC_ARRAY parameter contains no value.
8151
Code generation error at the SRC_ARRAY parameter.
8153
There is not enough free memory available at the SRC_ARRAY parameter.
8250
The Variant data type at the DEST_VARIABLE parameter contains no value.
8251
Code generation error at the DEST_VARIABLE parameter.
8254
Invalid data type at the DEST_VARIABLE parameter.
8382
The value at parameter POS is outside the limits of the array.
*You
can view the error codes as either integer or hexadecimal in the program editor.
Example: Deserialize instruction
The following example shows how the instruction works:
Network 1:
The "MOVE" instruction moves the value "0" to the "#BufferPos" data block tag. The
Deserialize instruction then deserializes the sequential representation of the customer data
from the "Buffer" data block and writes it to the "Target" data block. The Deserialize
instruction calculates the number of bytes that the converted data uses and stores it in the
"#BufferPos" data block tag.
Network 2:
The "Deserialize" instruction deserializes the sequential representation of the data stream
pointed to by "Buffer" and writes the characters to the "#Label" operand. The logic compares
the characters using the comparison instructions "arti" and "Bill". If the comparison for "arti" =
TRUE, the data is article data that is to be deserialized and written to the "Article" data
structure of the "Target" data block. If the comparison for "Bill" = TRUE, the data is billing
data that is to be deserialized and written to the "Bill" data structure of the "Target" data
block.
S7-1200 Programmable controller
270
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
Function block (or Function) interface:
Custom PLC data types:
The structure of the two PLC data types (UDTs) for this example are as follows:
Data blocks:
The two data blocks for this example are as follows:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
271
Basic instructions
8.6 Move operations
8.6.3
Serialize
You can use the "Serialize" instruction to convert several PLC data types (UDTs) to a
sequential representation without any loss of structure.
You can use the instruction to temporarily save multiple structured data items from your
program to a buffer, for example to a global data block, and send them to another CPU. The
memory area in which the converted PLC data types are stored must have the ARRAY of
BYTE data type and be declared with standard access. Make sure that there is enough
memory space prior to the conversion.
The POS parameter contains information about the number of bytes that the converted PLC
data types use.
Note
If you only want to send a single PLC data type (UDT), you can use the instruction "TSEND:
Send data via communication connection".
Table 8- 77
SERIALIZE instruction
LAD / FBD
Table 8- 78
SCL
ret_val := Serialize(
SRC_VARIABLE=>_variant_in_,
DEST_ARRAY:=_variant_out_,
POS:=_dint_inout_);
Description
Converts a PLC data type
(UDT) to a sequential representation.
Parameters for the SERIALIZE instruction
Parameter
Type
Data type
Description
SRC_VARIABLE
IN
Variant
PLC data type (UDT) that is
to be converted to a serial
representation
DEST_ARRAY
INOUT
Variant
Data block in which the generated data stream is to be
stored
POS
INOUT
DInt
Number of bytes that the
converted PLC data types
use. The calculated POS
parameter is zero-based.
RET_VAL
OUT
Int
Error information
S7-1200 Programmable controller
272
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
Table 8- 79
RET_VAL*
(W#16#...)
RET_VAL parameter
Description
0000
No error
80B0
The memory areas for the SRC_VARIABLE and DEST_ARRAY parameters overlap.
8150
The Variant data type at the SRC_VARIABLE parameter contains no value.
8152
Code generation error at the SRC_VARIABLE parameter.
8236
The data block at the DEST_ARRAY parameter is not a block with standard access.
8250
The Variant data type at the DEST_ARRAY parameter contains no value.
8252
Code generation error at the DEST_ARRAY parameter.
8253
There is not enough free memory available at the DEST_ARRAY parameter.
8254
Invalid data type at the DEST_VARIABLE parameter.
8382
The value at parameter POS is outside the limits of the array.
*You
can view the error codes as either integer or hexadecimal in the program editor.
Example: Serialize instruction
The following example shows how the instruction works:
Network 1:
The "MOVE" instruction moves the value "0" to the "#BufferPos" parameter. The "Serialize"
instruction serializes the customer data from the "Source" data block and writes it in
sequential representation to the "Buffer" data block. The instruction stores the number of
bytes used by the sequential representation in the "#BufferPos" parameter.
Network 2:
The logic now inserts some separator text to make it easier to deserialize the sequential
representation later. The "S_MOVE" instruction moves the text string "arti" to the "#Label"
parameter. The "Serialize" instruction writes these characters after the source client data to
the "Buffer" data block. The instruction adds the number of bytes in the text string "arti" to the
number already stored in the "#BufferPos" parameter.
Network 3:
The "Serialize" instruction serializes the data of a specific article, which is calculated in
runtime, from the "Source" data block and writes it in sequential representation to the
"Buffer" data block after the "arti" characters
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
273
Basic instructions
8.6 Move operations
Block Interface:
Custom PLC data types:
The structure of the two PLC data types (UDTs) for this example are as follows:
Data blocks:
The two data blocks for this example are as follows:
S7-1200 Programmable controller
274
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.4
Table 8- 80
LAD / FBD
FILL_BLK (Fill block) and UFILL_BLK (Fill block uninterruptible)
FILL_BLK and UFILL_BLK instructions
SCL
FILL_BLK(
in:=_variant_in,
count:=int,
out=>_variant_out);
UFILL_BLK(
in:=_variant_in,
count:=int,
out=>_variant_out);
Table 8- 81
Description
Interruptible fill instruction: Fills an address range with copies of a
specified data element
Uninterruptible fill instruction: Fills an address range with copies of
a specified data element
Data types for parameters
Parameter
Data type
Description
IN
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, Char, WChar
Data source address
COUNT
UDint, USInt, UInt
Number of data elements to copy
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, Char, WChar
Data destination address
Note
Rules for data fill operations
• To fill with the BOOL data type, use SET_BF, RESET_BF, R, S, or output coil (LAD)
• To fill with a single elementary data type, use MOVE
• To fill an array with an elementary data type, use FILL_BLK or UFILL_BLK
• To fill a single character in a string, use MOVE
• The FILL_BLK and UFILL_BLK instructions cannot be used to fill arrays in the I, Q, or M
memory areas.
The FILL_BLK and UFILL_BLK instructions copy the source data element IN to the
destination where the initial address is specified by the parameter OUT. The copy process
repeats and a block of adjacent addresses is filled until the number of copies is equal to the
COUNT parameter.
FILL_BLK and UFILL_BLK instructions differ in how interrupts are handled:
● Interrupt events are queued and processed during FILL_BLK execution. Use the
FILL_BLK instruction when the data at the move destination address is not used within an
interrupt OB subprogram or, if used, the destination data does not have to be consistent.
● Interrupt events are queued but not processed until UFILL_BLK execution is complete.
Use the UFILL_BLK instruction when the move operation must be completed and the
destination data consistent, before the execution of an interrupt OB subprogram.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
275
Basic instructions
8.6 Move operations
Table 8- 82
8.6.5
Table 8- 83
LAD / FBD
ENO status
ENO
Condition
Result
1
No error
The IN element was successfully copied to
all COUNT destinations.
0
The destination (OUT) range exceeds
the available memory area
Elements that fit are copied. No partial elements are copied.
SWAP (Swap bytes)
SWAP instruction
SCL
out := SWAP(in);
Description
Reverses the byte order for two-byte and four-byte data elements. No change
is made to the bit order within each byte. ENO is always TRUE following execution of the SWAP instruction.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 84
Data types for the parameters
Parameter
Data type
Description
IN
Word, DWord
Ordered data bytes IN
OUT
Word, DWord
Reverse ordered data bytes OUT
Example 1
Parameter IN = MB0
(before execution)
Parameter OUT = MB4,
(after execution)
Address
MW0
MB1
MW4
MB5
W#16#1234
12
34
34
12
WORD
MSB
LSB
MSB
LSB
Example 2
Parameter IN = MB0
(before execution)
Parameter OUT = MB4,
(after execution)
Address
MD0
MB1
MB2
MB3
MD4
MB5
MB6
MB7
DW#16#
12345678
12
34
56
78
78
56
34
12
DWORD
MSB
LSB
MSB
LSB
S7-1200 Programmable controller
276
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.6
Table 8- 85
LOWER_BOUND: (Read out ARRAY low limit)
LOWER_BOUND instruction
LAD / FBD
SCL
out := LOWER_BOUND(
ARR:=_variant_in_,
DIM:=_udint_in_);
Description
You can declare tags with ARRAY[*] in the block
interface. For these local tags, you can read out
the limits of the ARRAY. You will need to specify
the required dimension at the DIM parameter.
The LOWER_BOUND (Read out ARRAY low
limit). instruction lets you read out the variable
low limit of the ARRAY.
Parameters
The following table shows the parameters of the instruction "LOWER_BOUND: Read out
ARRAY low limit":
Parameters
Declaration
Data type
Memory area
Description
EN
Input
BOOL
I, Q, M, D, L
Enable input
ENO
Output
BOOL
I, Q, M, D, L
Enable output ENO has the
signal state "0" if one of the
following conditions applies:
•
The EN enable input has
the signal state "0".
•
The dimension specified
at input DIM does not exist.
ARR
Input
ARRAY [*]
FB: Section InOut ARRAY of which the variable
FC: Sections Input low limit is to be read.
and InOut
DIM
Input
UDINT
I, Q, M, D, L or
constant
Dimension of the ARRAY of
which the variable low limit is
to be read.
OUT
Output
DINT
I, Q, M, D, L
Result
You can find additional information on valid data types under "Data types (Page 125)":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
277
Basic instructions
8.6 Move operations
Example
In the function (FC) block interface, the input parameter ARRAY_A is a one-dimensional
array with variable dimensions.
If the "Enable_Start" operand returns signal state "1", the CPU executes the
LOWER_BOUND instruction. It reads out the variable low limit of the ARRAY #ARRAY_A
from the one-dimensional array. If the instruction executes without errors, it sets operand
"Enable_Out" and sets the "Result" operand to the low limit of the array.
S7-1200 Programmable controller
278
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.7
Table 8- 86
UPPER_BOUND: (Read out ARRAY high limit)
LOWER_BOUND instruction
LAD / FBD
SCL
out := UPPER_BOUND(
ARR:=_variant_in_,
DIM:=_udint_in_);
Description
You can declare tags with ARRAY[*] in the block
interface. For these local tags, you can read out
the limits of the ARRAY. You will need to specify
the required dimension at the DIM parameter.
The UPPER_BOUND (Read out ARRAY high
limit) instruction lets you read out the variable
high limit of the ARRAY.
Parameters
The following table shows the parameters of the instruction "UPPER_BOUND: Read out
ARRAY high limit":
Parameters
Declaration
Data type
Memory area
Description
EN
Input
BOOL
I, Q, M, D, L
Enable input
ENO
Output
BOOL
I, Q, M, D, L
Enable output
ARR
Input
ARRAY [*]
FB: Section InOut ARRAY of which the variable
FC: Sections Input high limit is to be read.
and InOut
DIM
Input
UDINT
I, Q, M, D, L or
constant
Dimension of the ARRAY of
which the variable high limit
is to be read.
OUT
Output
DINT
I, Q, M, D, L
Result
You can find additional information on valid data types under "Data types (Page 125)":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
279
Basic instructions
8.6 Move operations
Example
In the function (FC) block interface, the input parameter ARRAY_A is a one-dimensional
array with variable dimensions.
If the "Enable_Start" operand returns signal state "1", the CPU executes the instruction. It
reads out the variable high limit of the ARRAY #ARRAY_A from the one-dimensional array. If
the instruction executes without errors, it sets operand "Enable_Out" and sets the "Result"
operand.
S7-1200 Programmable controller
280
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.8
Read / Write memory instructions
8.6.8.1
PEEK and POKE (SCL only)
SCL provides PEEK and POKE instructions that allow you to read from or write to data
blocks, I/O, or memory. You provide parameters for specific byte offsets or bit offsets for the
operation.
Note
To use the PEEK and POKE instructions with data blocks, you must use standard (not
optimized) data blocks. Also note that the PEEK and POKE instructions merely transfer data.
They have no knowledge of data types at the addresses.
PEEK(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
Reads the byte referenced by byteOffset of
the referenced data block, I/O or memory
area.
Example referencing data block:
%MB100 := PEEK(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Example referencing IB3 input:
PEEK_WORD(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
%MB100 := PEEK(area:=16#81,
dbNumber:=0, byteOffset:=#i); // when
#i = 3
Reads the word referenced by byteOffset of
the referenced data block, I/O or memory
area.
Example:
PEEK_DWORD(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_);
%MW200 := PEEK_WORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Reads the double word referenced by
byteOffset of the referenced data block, I/O or
memory area.
Example:
PEEK_BOOL(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
bitOffset:=_in_);
%MD300 := PEEK_DWORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
Reads a Boolean referenced by the bitOffset
and byteOffset of the referenced data block,
I/O or memory area
Example:
%MB100.0 := PEEK_BOOL(area:=16#84,
dbNumber:=1, byteOffset:=#ii,
bitOffset:=#j);
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
281
Basic instructions
8.6 Move operations
POKE(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
value:=_in_);
Writes the value (Byte, Word, or DWord) to
the referenced byteOffset of the referenced
data block, I/O or memory area
Example referencing data block:
POKE(area:=16#84, dbNumber:=2,
byteOffset:=3, value:="Tag_1");
Example referencing QB3 output:
POKE_BOOL(area:=_in_,
dbNumber:=_in_,
byteOffset:=_in_,
bitOffset:=_in_,
value:=_in_);
POKE_BLK(area_src:=_in_,
dbNumber_src:=_in_,
byteOffset_src:=_in_,
area_dest:=_in_,
dbNumber_dest:=_in_,
byteOffset_dest:=_in_,
count:=_in_);
POKE(area:=16#82, dbNumber:=0,
byteOffset:=3, value:="Tag_1");
Writes the Boolean value to the referenced
bitOffset and byteOffset of the referenced
data block, I/O or memory area
Example:
POKE_BOOL(area:=16#84, dbNumber:=2,
byteOffset:=3, bitOffset:=5, value:=0);
Writes "count" number of bytes starting at the
referenced byte Offset of the referenced
source data block, I/O or memory area to the
referenced byteOffset of the referenced destination data block, I/O or memory area
Example:
POKE_BLK(area_src:=16#84,
dbNumber_src:=#src_db, byteOffset_src:=#src_byte, area_dest:=16#84,
dbNumber_dest:=#src_db, byteOffset_dest:=#src_byte, count:=10);
For PEEK and POKE instructions, the following values for the "area", "area_src" and
"area_dest" parameters are applicable. For areas other than data blocks, the dbNumber
parameter must be 0.
16#81
I
16#82
Q
16#83
M
16#84
DB
S7-1200 Programmable controller
282
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.8.2
Read and write big and little Endian instructions (SCL)
The S7-1200 CPU provides SCL instructions for reading and writing data in little endian
format and in big endian format. Little endian format means that the byte with the least
significant bit is in the lowest memory address. Big endian format means that the byte with
the most significant bit is in the lowest memory address.
The four SCL instructions for reading and writing data in little endian and big endian format
are as follows:
● READ_LITTLE (Read data in little endian format)
● WRITE_LITTLE (Write data in little endian format)
● READ_BIG (Read data in big endian format)
● WRITE_BIG (Write data in big endian format)
Table 8- 87
Read and write big and little endian instructions
LAD / FBD
SCL
READ_LITTLE(
src_array:=_variant_in_,
dest_Variable =>_out_,
pos:=_dint_inout)
WRITE_LITTLE(
src_variable:=_in_,
dest_array =>_variant_inout_,
pos:=_dint_inout)
READ_BIG(
src_array:=_variant_in_,
dest_Variable =>_out_,
pos:=_dint_inout)
WRITE_BIG(
src_variable:=_in_,
dest_array =>_variant_inout_,
pos:=_dint_inout)
Not available
Not available
Not available
Not available
Table 8- 88
Description
Reads data from a memory area and writes it to a
single tag in little endian byte format.
Writes data from a single tag to a memory area in little
endian byte format.
Reads data from a memory area and writes it to a
single tag in big endian byte format.
Writes data from a single tag to a memory area in big
endian byte format.
Parameters for the READ_LITTLE and READ_BIG instructions
Parameter
Data type
Description
src_array
Array of Byte
Memory area from which to read
data
dest_Variable
Bit strings, integers, floating-point numbers, timers, date and
time, character strings
Destination variable at which to
write data
pos
DINT
Zero-based position from which to
start reading data from the
src_array input.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
283
Basic instructions
8.6 Move operations
Table 8- 89
Parameters for the WRITE_LITTLE and WRITE_BIG instructions
Parameter
Data type
src_variable
Bit strings, integers, floating-point numbers, LDT, TOD, LTOD, Source data from tag
DATA, Char, WChar
dest_array
Array of Byte
Memory area at which to write data
pos
DINT
Zero-based position at which to
start writing data into the dest_array
output.
Table 8- 90
Description
RET_VAL parameter
RET_VAL*
(W#16#...)
Description
0000
No error
80B4
The SRC_ARRAY or DEST_ARRAY is not an Array of Byte
8382
The value at parameter POS is outside the limits of the array.
8383
The value at parameter POS is within the limits of the Array but the size of the memory area exceeds the
high limit of the array.
*You
can view the error codes as either integer or hexadecimal in the program editor.
S7-1200 Programmable controller
284
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.9
Variant instructions
8.6.9.1
VariantGet (Read VARIANT tag value)
You can use the "Read out Variant tag value" instruction to read the value of the tag to which
the Variant pointer at the SRC parameter points and write it in the tag at the DST parameter.
The SRC parameter has the Variant data type. Any data type except for Variant can be
specified at the DST parameter.
The data type of the tag at the DST parameter must match the data type to which the Variant
points.
Table 8- 91
LAD / FBD
VariantGet instruction
SCL
VariantGet(
SRC:=_variant_in_,
DST=>_variant_out_);
Description
Reads the tag pointed to by the SRC parameter and writes it to
the tag at the DST parameter
Note
To copy structures and arrays, you can use the "MOVE_BLK_VARIANT: Move block"
instruction.
Table 8- 92
Parameters for the VariantGet instruction
Parameter
Data type
Description
SRC
Variant
Pointer to source data
DST
Bit strings, integers, floating-point numbers, timers, date and
time, character strings, ARRAY elements, PLC data types
Destination at which to write data
Table 8- 93
ENO status
ENO
Condition
Result
1
No error
Instruction copied the tag data pointed to by
SRC to the DST tag.
0
Enable input EN has the signal state "0" or the data types Instruction copied no data.
do not correspond.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
285
Basic instructions
8.6 Move operations
8.6.9.2
VariantPut (Write VARIANT tag value)
You can use the "Write VARIANT tag value" instruction to write the value of the tag at the
SRC parameter to the tag at the DST parameter to which the VARIANT points.
The DST parameter has the VARIANT data type. Any data type except for VARIANT can be
specified at the SRC parameter.
The data type of the tag at the SRC parameter must match the data type to which the
VARIANT points.
Table 8- 94
LAD / FBD
VariantPut instruction
SCL
VariantPut(
SRC:=_variant_in_,
DST=>_variant_in_);
Description
Writes the tag referenced by the SRC parameter to the variant
pointed to by the DST parameter
Note
To copy structures and ARRAYs, you can use the "MOVE_BLK_VARIANT: Move block"
instruction.
Table 8- 95
Parameters for the VariantPut instruction
Parameter
Data type
Description
SRC
Bit strings, integers, floating-point numbers, timers, date and
time, character strings, ARRAY elements, PLC data types
Pointer to source data
DST
Variant
Destination at which to write data
Table 8- 96
ENO status
ENO
Condition
Result
1
No error
Instruction copied the SRC tag data to the DST
tag.
0
Enable input EN has the signal state "0" or the data types Instruction copied no data.
do not correspond.
S7-1200 Programmable controller
286
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
8.6.9.3
CountOfElements (Get number of ARRAY elements)
You can use the "Get number of ARRAY elements" instruction to query how many Array
elements are in a tag pointed to by a Variant.
If it is a one-dimensional ARRAY, the instruction returns the difference between the high and
low limit +1 is output. If it is a multi-dimensional ARRAY, the instruction returns the product of
all dimensions.
Table 8- 97
CountOfElements instruction
LAD / FBD
SCL
Description
Result := CountOfElements(
_variant_in_);
Counts the number of array elements at
the array pointed to by the IN parameter.
Note
If the Variant points to an Array of Bool, the instruction counts the fill elements to the nearest
byte boundary. For example, the instruction returns 8 as the count for an Array[0..1] of Bool.
Table 8- 98
Parameters for the CountOfElements instruction
Parameter
Data type
Description
IN
Variant
Tag with array elements to be
counted
RET_VAL
UDint
Instruction result
Table 8- 99
ENO status
ENO
Condition
Result
1
No error
Instruction returns the number of array elements.
0
Enable input EN has the signal state "0" or the Variant
does not point to an array.
Instruction returns 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
287
Basic instructions
8.6 Move operations
8.6.10
Legacy instructions
8.6.10.1
FieldRead (Read field) and FieldWrite (Write field) instructions
Note
STEP 7 V10.5 did not support a variable reference as an array index or multi-dimensional
arrays. The FieldRead and FieldWrite instructions were used to provide variable array index
operations for a one-dimensional array. STEP 7 V11 and greater do support a variable as an
array index and multi-dimensional arrays. FieldRead and FieldWrite are included in STEP 7
V11 and greater for backward compatibility with programs that have used these instructions.
Table 8- 100 FieldRead and FieldWrite instructions
LAD / FBD
SCL
value := member[index];
member[index] := value;
1
Description
FieldRead reads the array element with the index
value INDEX from the array whose first element in
specified by the MEMBER parameter. The value of
the array element is transferred to the location specified at the VALUE parameter.
WriteField transfers the value at the location specified
by the VALUE parameter to the array whose first
element is specified by the MEMBER parameter. The
value is transferred to the array element whose array
index is specified by the INDEX parameter.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
Table 8- 101 Data types for parameters
1
Parameter and type
Data type
Description
Index
Input
DInt
The index number of the array element to be read or
written to
Member 1
Input
Binary numbers, integers, float- Location of the first element in a one- dimension
ing-point numbers, timers,
array defined in a global data block or block interDATE, TOD, CHAR and
face.
WCHAR as components of an
For example: If the array index is specified as [-2..4],
ARRAY tag
then the index of the first element is -2 and not 0.
Value 1
Out
Binary numbers, integers, float- Location to which the specified array element is
ing-point numbers, timers,
copied (FieldRead)
DATE, TOD, CHAR, WCHAR
Location of the value that is copied to the specified
array element (FieldWrite)
The data type of the array element specified by the MEMBER parameter and the VALUE parameter must have the
same data type.
S7-1200 Programmable controller
288
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.6 Move operations
The enable output ENO = 0, if one of the following conditions applies:
● The EN input has signal state "0"
● The array element specified at the INDEX parameter is not defined in the array
referenced at MEMBER parameter
● Errors such as an overflow occur during processing
Example: Accessing data by array indexing
To access elements of an array with a variable, simply use the variable as an array index in
your program logic. For example, the network below sets an output based on the Boolean
value of an array of Booleans in "Data_block_1" referenced by the PLC tag "Index".
The logic with the variable array index is equivalent to the former method using the
FieldRead instruction:
FieldWrite and FieldRead instructions can be replaced with variable array indexing logic.
SCL has no FieldRead or FieldWrite instructions, but supports indirect addressing of an
array with a variable:
#Tag_1 := "Data_block_1".Bool_Array[#Index];
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
289
Basic instructions
8.7 Conversion operations
8.7
Conversion operations
8.7.1
CONV (Convert value)
Table 8- 102 Convert (CONV) instruction
LAD / FBD
SCL
out := _TO_(in);
Description
Converts a data element from one
data type to another data type.
1
For LAD and FBD: Click the "???" and select the data types from the drop-down menu.
2
For SCL: Construct the conversion instruction by identifying the data type for the input parameter (in) and output parameter (out). For example, DWORD_TO_REAL converts a DWord value to a Real value.
Table 8- 103 Data types for the parameters
Parameter
Data type
Description
string1,
IN
Bit
SInt, USInt, Int, UInt, DInt, UDInt, Real, LReal,
BCD16, BCD32, Char, WChar
Input value
OUT
Bit string1, SInt, USInt, Int, UInt, DInt, UDInt, Real, LReal,
BCD16, BCD32, Char, WChar
Input value converted to a new data type
The instruction does not allow you to select Bit strings (Byte, Word, DWord). To enter an operand of data type Byte,
Word, or DWord for a parameter of the instruction, select an unsigned integer with the same bit length. For example, select USInt for a Byte, UInt for a Word, or UDInt for a DWord.
1
After you select the (convert from) data type, a list of possible conversions is shown in the
(convert to) dropdown list. Conversions from and to BCD16 are restricted to the Int data
type. Conversions from and to BCD32 are restricted to the DInt data type.
Table 8- 104 ENO status
ENO
Description
Result OUT
1
No error
Valid result
0
IN is +/- INF or +/- NaN
+/- INF or +/- NaN
0
Result exceeds valid range for OUT data type
OUT is set to the IN value
S7-1200 Programmable controller
290
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
8.7.2
Conversion instructions for SCL
Conversion instructions for SCL
Table 8- 105 Conversion from a Bool, Byte, Word, or DWord
Data type
Bool
Byte
Instruction
BOOL_TO_BYTE, BOOL_TO_WORD,
BOOL_TO_DWORD, BOOL_TO_INT,
BOOL_TO_DINT
BYTE_TO_BOOL
Result
BYTE_TO_WORD, BYTE_TO_DWORD
The value is transferred to the least significant byte of the
target data type.
BYTE_TO_SINT, BYTE_TO_USINT
Word
BYTE_TO_INT, BYTE_TO_UINT,
BYTE_TO_DINT, BYTE_TO_UDINT
WORD_TO_BOOL
WORD_TO_BYTE
WORD_TO_DWORD
WORD_TO_SINT, WORD_TO_USINT
WORD_TO_INT, WORD_TO_UINT
WORD_TO_DINT, WORD_TO_UDINT
DWord
DWORD_TO_BOOL
DWORD_TO_BYTE, DWORD_TO_WORD,
DWORD_TO_SINT
DWORD_TO_USINT, DWORD_TO_INT,
DWORD_TO_UINT
DWORD_TO_DINT, DWORD_TO_UDINT,
DWORD_TO_REAL
The value is transferred to the least significant bit of the
target data type.
The least significant bit is transferred into the destination
data type.
The value is transferred to the target data type.
The value is transferred to the least significant byte of the
target data type.
The least significant bit is transferred into the destination
data type.
The least significant byte of the source value is transferred to the target data type
The value is transferred to the least significant word of
the target data type.
The least significant byte of the source value is transferred to the target data type.
The value is transferred to the target data type.
The value is transferred to the least significant word of
the target data type.
The least significant bit is transferred into the destination
data type.
The least significant byte of the source value is transferred to the target data type.
The least significant word of the source value is transferred to the target data type.
The value is transferred to the target data type.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
291
Basic instructions
8.7 Conversion operations
Table 8- 106 Conversion from a short integer (SInt or USInt)
Data type
SInt
Instruction
SINT_TO_BOOL
Result
The least significant bit is transferred into the destination
data type.
SINT_TO_BYTE
SINT_TO_WORD, SINT_TO_DWORD
USInt
SINT_TO_INT, SINT_TO_DINT,
SINT_TO_USINT, SINT_TO_UINT,
SINT_TO_UDINT, SINT_TO_REAL,
SINT_TO_LREAL, SINT_TO_CHAR,
SINT_TO_STRING
USINT_TO_BOOL
USINT_TO_BYTE
USINT_TO_WORD, USINT_TO_DWORD,
USINT_TO_INT, USINT_TO_UINT,
USINT_TO_DINT, USINT_TO_UDINT
USINT_TO_SINT, USINT_TO_REAL,
USINT_TO_LREAL, USINT_TO_CHAR,
USINT_TO_STRING
The value is transferred to the target data type
The value is transferred to the least significant byte of the
target data type.
The value is converted.
The least significant bit is transferred into the destination
data type.
The value is transferred to the target data type
The value is transferred to the least significant byte of the
target data type.
The value is converted.
Table 8- 107 Conversion from an integer (Int or UInt)
Data type
Int
instruction
INT_TO_BOOL
INT_TO_BYTE,
INT_TO_SINT,
INT_TO_UINT,
INT_TO_REAL,
INT_TO_CHAR,
INT_TO_WORD
Result
INT_TO_DWORD,
INT_TO_USINT,
INT_TO_UDINT,
INT_TO_LREAL,
INT_TO_STRING
INT_TO_DINT
UInt
UINT_TO_BOOL
UINT_TO_BYTE, UINT_TO_SINT,
UINT_TO_USINT, UINT_TO_INT,
UINT_TO_REAL, UINT_TO_LREAL,
UINT_TO_CHAR, UINT_TO_STRING
UINT_TO_WORD, UINT_TO_DATE
UINT_TO_DWORD, UINT_TO_DINT,
UINT_TO_UDINT
The least significant bit is transferred into the destination
data type.
The value is converted.
The value is transferred to the target data type.
The value is transferred to the least significant byte of the
target data type.
The least significant bit is transferred into the destination
data type.
The value is converted.
The value is transferred to the target data type.
The value is transferred to the least significant byte of the
target data type.
S7-1200 Programmable controller
292
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
Table 8- 108 Conversion from a double integer (Dint or UDInt)
Data type
DInt
Instruction
DINT_TO_BOOL
Result
DINT_TO_BYTE, DINT_TO_WORD, DINT_TO_SINT,
DINT_TO_USINT, DINT_TO_INT, DINT_TO_UINT,
DINT_TO_UDINT, DINT_TO_REAL, DINT_TO_LREAL,
DINT_TO_CHAR, DINT_TO_STRING
DINT_TO_DWORD, DINT_TO_TIME
UDInt
UDINT_TO_BOOL
UDINT_TO_BYTE, UDINT_TO_WORD, UDINT_TO_SINT,
UDINT_TO_USINT, UDINT_TO_INT, UDINT_TO_UINT,
UDINT_TO_DINT, UDINT_TO_REAL, UDINT_TO_LREAL,
UDINT_TO_CHAR, UDINT_TO_STRING
UDINT_TO_DWORD, UDINT_TO_TOD
The least significant bit is transferred
into the destination data type.
The value is converted.
The value is transferred to the target
data type.
The least significant bit is transferred
into the destination data type.
The value is converted.
The value is transferred to the target
data type.
Table 8- 109 Conversion from a Real number (Real or LReal)
Data type
Real
LReal
Instruction
REAL_TO_DWORD, REAL_TO_LREAL
Result
REAL_TO_SINT, REAL_TO_USINT, REAL_TO_INT,
REAL_TO_UINT, REAL_TO_DINT, REAL_TO_UDINT,
REAL_TO_STRING
LREAL_TO_SINT, LREAL_TO_USINT, LREAL_TO_INT,
LREAL_TO_UINT, LREAL_TO_DINT, LREAL_TO_UDINT,
LREAL_TO_REAL, LREAL_TO_STRING
The value is converted.
The value is transferred to the target
data type.
The value is converted.
Table 8- 110 Conversion from Time, DTL, TOD or Date
Data type
Time
DTL
TOD
Date
Instruction
TIME_TO_DINT
Result
TOD_TO_UDINT
The value is converted.
DTL_TO_DATE, DTL_TO_TOD
DATE_TO_UINT
The value is transferred to the target data type.
The value is converted.
The value is converted.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
293
Basic instructions
8.7 Conversion operations
Table 8- 111 Conversion from a Char or String
Data type
Char
String
8.7.3
Instruction
CHAR_TO_SINT, CHAR_TO_USINT,
CHAR_TO_INT, CHAR_TO_UINT,
CHAR_TO_DINT, CHAR_TO_UDINT
CHAR_TO_STRING
Result
STRING_TO_SINT, STRING_TO_USINT,
STRING_TO_INT, STRING_TO_UINT,
STRING_TO_DINT, STRING_TO_UDINT,
STRING_TO_REAL, STRING_TO_LREAL
STRING_TO_CHAR
The value is converted.
The value is converted.
The value is transferred to the first character of
the string.
The first character of the string is copied to the
Char.
ROUND (Round numerical value) and TRUNC (Truncate numerical value)
Table 8- 112 ROUND and TRUNC instructions
LAD / FBD
SCL
out := ROUND (in);
Description
Converts a real number to an integer. For LAD/FBD, you click the "???" in
the instruction box to select the data type for the output, for example "DInt".
For SCL, the default data type for the output of the ROUND instruction is
DINT. To round to another output data type, enter the instruction name with
the explicit name of the data type, for example, ROUND_REAL or
ROUND_LREAL.
The real number fraction is rounded to the nearest integer value (IEEE round to nearest). If the number is exactly one-half the span between two
integers (for example, 10.5), then the number is rounded to the even integer. For example:
out := TRUNC(in);
•
ROUND (10.5) = 10
•
ROUND (11.5) = 12
TRUNC converts a real number to an integer. The fractional part of the real
number is truncated to zero (IEEE - round to zero).
For LAD and FBD: Click the "???" (by the instruction name) and select a data type from the drop-down menu.
1
Table 8- 113 Data types for the parameters
Parameter
Data type
Description
IN
Real, LReal
Floating point input
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Rounded or truncated output
S7-1200 Programmable controller
294
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
Table 8- 114 ENO status
ENO
Description
Result OUT
1
No error
Valid result
0
IN is +/- INF or +/- NaN
+/- INF or +/- NaN
8.7.4
CEIL and FLOOR (Generate next higher and lower integer from floating-point
number)
Table 8- 115 CEIL and FLOOR instructions
LAD / FBD
SCL
out := CEIL(in);
Description
out := FLOOR(in);
Converts a real number (Real or LReal) to the closest integer
smaller than or equal to the selected real number (IEEE "round
to -infinity").
Converts a real number (Real or LReal) to the closest integer
greater than or equal to the selected real number (IEEE "round
to +infinity").
For LAD and FBD: Click the "???" (by the instruction name) and select a data type from the drop-down menu.
1
Table 8- 116 Data types for the parameters
Parameter
Data type
Description
IN
Real, LReal
Floating point input
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Converted output
Table 8- 117 ENO status
ENO
Description
Result OUT
1
No error
Valid result
0
IN is +/- INF or +/- NaN
+/- INF or +/- NaN
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
295
Basic instructions
8.7 Conversion operations
8.7.5
SCALE_X (Scale) and NORM_X (Normalize)
Table 8- 118 SCALE_X and NORM_X instructions
LAD / FBD
SCL
out :=SCALE_X(min:=_in_,
value:=_in_,
max:=_in_);
Description
Scales the normalized real parameter VALUE
where ( 0.0 <= VALUE <= 1.0 ) in the data type
and value range specified by the MIN and MAX
parameters:
OUT = VALUE (MAX - MIN) + MIN
out :=NORM_X(min:=_in_,
value:=_in_,
max:=_in_);
1
Normalizes the parameter VALUE inside the
value range specified by the MIN and MAX parameters:
OUT = (VALUE - MIN) / (MAX - MIN),
where ( 0.0 <= OUT <= 1.0 )
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
Table 8- 119 Data types for the parameters
Parameter
Data type1
Description
MIN
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Input minimum value for range
VALUE
SCALE_X: Real, LReal
Input value to scale or normalize
NORM_X: SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
MAX
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Input maximum value for range
OUT
SCALE_X: SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal
Scaled or normalized output value
NORM_X: Real, LReal
1
For SCALE_X: Parameters MIN, MAX, and OUT must be the same data type.
For NORM_X: Parameters MIN, VALUE, and MAX must be the same data type.
S7-1200 Programmable controller
296
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
Note
SCALE_X parameter VALUE should be restricted to ( 0.0 <= VALUE <= 1.0 )
If parameter VALUE is less than 0.0 or greater than 1.0:
• The linear scaling operation can produce OUT values that are less than the parameter
MIN value or above the parameter MAX value for OUT values that fit within the value
range of the OUT data type. SCALE_X execution sets ENO = TRUE for these cases.
• It is possible to generate scaled numbers that are not within the range of the OUT data
type. For these cases, the parameter OUT value is set to an intermediate value equal to
the least-significant portion of the scaled real number prior to final conversion to the OUT
data type. SCALE_X execution sets ENO = FALSE in this case.
NORM_X parameter VALUE should be restricted to ( MIN <= VALUE <= MAX )
If parameter VALUE is less than MIN or greater than MAX, the linear scaling operation can
produce normalized OUT values that are less than 0.0 or greater than 1.0. NORM_X
execution sets ENO = TRUE in this case.
Table 8- 120 ENO status
ENO
Condition
Result OUT
1
No error
Valid result
0
Result exceeds valid range for the OUT data
type
Intermediate result: The least-significant portion of a real
number prior to final conversion to the OUT data type.
0
Parameters MAX <= MIN
SCALE_X: The least-significant portion of the Real number
VALUE to fill up the OUT size.
NORM_X: VALUE in VALUE data type extended to fill a
double word size.
0
Parameter VALUE = +/- INF or +/- NaN
VALUE is written to OUT
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
297
Basic instructions
8.7 Conversion operations
Example (LAD): normalizing and scaling an analog input value
An analog input from an analog signal module or signal board using input in current is in the
range 0 to 27648 for valid values. Suppose an analog input represents a temperature where
the 0 value of the analog input represents -30.0 degrees C and 27648 represents 70.0
degrees C.
To transform the analog value to the corresponding engineering units, normalize the input to
a value between 0.0 and 1.0, and then scale it between -30.0 and 70.0. The resulting value
is the temperature represented by the analog input in degrees C:
Note that if the analog input was from an analog signal module or signal board using voltage,
the MIN value for the NORM_X instruction would be -27648 instead of 0.
Example (LAD): normalizing and scaling an analog output value
An analog output to be set in an analog signal module or signal board using output in current
must be in the range 0 to 27648 for valid values. Suppose an analog output represents a
temperature setting where the 0 value of the analog input represents -30.0 degrees C and
27648 represents 70.0 degrees C. To convert a temperature value in memory that is
between -30.0 and 70.0 to a value for the analog output in the range 0 to 27648, you must
normalize the value in engineering units to a value between 0.0 and 1.0, and then scale it to
the range of the analog output, 0 to 27648:
Note that if the analog output was for an analog signal module or signal board using voltage,
the MIN value for the SCALE_X instruction would be -27648 instead of 0.
Additional information on analog input representations (Page 1471) and analog output
representations (Page 1472) in both voltage and current can be found in the Technical
Specifications.
S7-1200 Programmable controller
298
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
8.7.6
Variant conversion instructions
8.7.6.1
VARIANT_TO_DB_ANY (Convert VARIANT to DB_ANY)
You use the "VARIANT to DB_ANY" instruction to read the operand at the IN parameter and
convert it to the data type DB_ANY. The IN parameter is of the Variant data type and
represents either an instance data block or an ARRAY data block. When you create the
program, you do not need to know which data block corresponds to the IN parameter. The
instruction reads the data block number during runtime and writes it to the operand at the
RET_VAL parameter.
Table 8- 121 VARIANT_TO_DB_ANY instruction
LAD / FBD
Not available
SCL
RET_VAL :=
VARIANT_TO_DB_ANY(
in := _variant_in_,
err => _int_out_);
Description
Reads the operand from the Variant IN parameter and stores it
in the function result, which is of the type DB_ANY
Table 8- 122 Parameters for the VARIANT_TO_DB_ANY instruction
Parameter
Data type
Description
IN
Variant
Variant that represents and instance data
block or an array data block
RET_VAL
DB_ANY
Output DB_ANY data type that contains the
converted data block number
ERR
Int
Error information
Table 8- 123 ENO status
ENO
Condition
Result
1
No error
Instruction converts the input Variant and
stores it in the DB_ANY function output
0
Enable input EN has the signal state "0" or the IN parameter is invalid.
Instruction does nothing.
Table 8- 124 Error output codes for the VARIANT_TO_DB_ANY instruction
Err
Description
(W#16#...)
0000
No error
252C
The Variant data type at IN parameter has the value 0. The CPU
changes to STOP mode.
8131
The data block does not exist or is too short (first access).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
299
Basic instructions
8.7 Conversion operations
Err
Description
(W#16#...)
8132
The data block is too short and not an Array data block (second
access).
8134
The data block is write-protected
8150
The data type Variant at parameter IN provides the value "0". To
receive this error message, the "Handle errors within block" block
property must be activated. Otherwise the CPU changes to STOP
mode and sends the error code 16#252C
8154
The data block has the incorrect data type.
*You can display error codes in the program editor as integer or hexadecimal values.
8.7.6.2
DB_ANY_TO_VARIANT (Convert DB_ANY to VARIANT)
You use the "DB_ANY to VARIANT" instruction to read the number of a data block that
meets the requirements listed below. The operand at the IN parameter has the data type
DB_ANY, which means you do not need to know during program creation which data block is
to be read. The instruction reads the data block number during runtime and writes it to the
function result RET_VAL by means of a VARIANT pointer.
Table 8- 125 DB_ANY_TO_VARIANT instruction
LAD / FBD
Not available
SCL
RET_VAL :=
DB_ANY_TO_VARIANT(
in := _db_any_in_,
err => _int_out_);
Description
Reads the data block number from the Variant IN parameter and
stores it in the function result, which is of the type Variant
Table 8- 126 Parameters for the DB_ANY_TO_VARIANT instruction
Parameter
Data type
Description
IN
DB_ANY
Variant that contains the data block number
RET_VAL
Variant
Output DB_ANY data type that contains the
converted data block number
ERR
Int
Error information
Table 8- 127 ENO status
ENO
Condition
Result
1
No error
Instruction converts the data block number in
the variant and stores it in the function DB_ANY
output
0
Enable input EN has the signal state "0" or the IN
parameter is invalid.
Instruction does nothing.
S7-1200 Programmable controller
300
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.7 Conversion operations
Table 8- 128 Error output codes for the DB_ANY_TO_VARIANT instruction
Err
Description
(W#16#...)
0000
No error
8130
The number of the data block is 0.
8131
The data block does not exist or is too short.
8132
The data block is too short and not an Array data block.
8134
The data block is write-protected.
8154
The data block has the incorrect data type.
8155
Unknown type code
*You can display error codes in the program editor as integer or hexadecimal values.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
301
Basic instructions
8.8 Program control operations
8.8
Program control operations
8.8.1
JMP (Jump if RLO = 1), JMPN (Jump if RLO = 0), and Label (Jump label)
instructions
Table 8- 129 JMP, JMPN, and LABEL instruction
LAD
FBD
SCL
Description
See the GOTO (Page 325)
statement.
Jump if RLO (result of logic operation) = 1:
If there is power flow to a JMP coil (LAD), or if the
JMP box input is true (FBD), then program execution
continues with the first instruction following the specified label.
Jump if RLO = 0:
If there is no power flow to a JMPN coil (LAD), or if
the JMPN box input is false (FBD), then program
execution continues with the first instruction following
the specified label.
Destination label for a JMP or JMPN jump instruction.
1
You create your label names by typing in the LABEL instruction directly. Use the parameter helper icon to select the
available label names for the JMP and JMPN label name field. You can also type a label name directly into the JMP or
JMPN instruction.
Table 8- 130 Data types for the parameters
Parameter
Data type
Description
Label_name
Label identifier
Identifier for Jump instructions and the corresponding jump destination program label
● Each label must be unique within a code block.
● You can jump within a code block, but you cannot jump from one code block to another
code block.
● You can jump forward or backward.
● You can jump to the same label from more than one place in the same code block.
S7-1200 Programmable controller
302
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.2
JMP_LIST (Define jump list)
Table 8- 131 JMP_LIST instruction
LAD / FBD
SCL
CASE k OF
0: GOTO
1: GOTO
2: GOTO
[n: GOTO
END_CASE;
Description
dest0;
dest1;
dest2;
destn;]
The JMP_LIST instruction acts as a program jump distributor to control
the execution of program sections. Depending on the value of the K
input, a jump occurs to the corresponding program label. Program execution continues with the program instructions that follow the destination
jump label. If the value of the K input exceeds the number of labels - 1,
then no jump occurs and processing continues with the next program
network.
Table 8- 132 Data types for parameters
Parameter
Data type
Description
K
UInt
Jump distributor control value
DEST0, DEST1, ..,
DESTn.
Program Labels
Jump destination labels corresponding to specific K parameter values:
If the value of K equals 0, then a jump occurs to the program label assigned to the DEST0 output. If the value of K equals 1, then a jump occurs to the program label assigned to the DEST1 output, and so on. If the
value of the K input exceeds the (number of labels - 1), then no jump
occurs and processing continues with the next program network.
For LAD and FBD: When the JMP_LIST box is first placed in your program, there are two
jump label outputs. You can add or delete jump destinations.
Click the create icon inside the box (on the left of the last DEST parameter)
to add new outputs for jump labels.
• Right-click on an output stub and select the "Insert output" command.
• Right-click on an output stub and select the "Delete" command.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
303
Basic instructions
8.8 Program control operations
8.8.3
SWITCH (Jump distributor)
Table 8- 133 SWITCH instruction
LAD / FBD
SCL
Not available
Description
The SWITCH instruction acts as a program jump distributor to
control the execution of program sections. Depending on the result of comparisons between the value of the K input and the
values assigned to the specified comparison inputs, a jump occurs
to the program label that corresponds to the first comparison test
that is true. If none of the comparisons is true, then a jump to the
label assigned to ELSE occurs. Program execution continues with
the program instructions that follow the destination jump label.
1
For LAD and FBD: Click below the box name and select a data type from the drop-down menu.
2
For SCL: Use an IF-THEN set of comparisons.
Table 8- 134 Data types for parameters
Parameter
Data type1
Description
K
UInt
Common comparison value input
==, <>, <, <=, >. >= SInt, Int, DInt, USInt, UInt, UDInt, Real, Separate comparison value inputs for specific comparison
LReal, Byte, Word, DWord, Time,
types
TOD, Date
DEST0, DEST1, ..,
DESTn, ELSE
Program Labels
Jump destination labels corresponding to specific comparisons:
The comparison input below and next to the K input is processed first and causes a jump to the label assigned to
DEST0, if the comparison between the K value and this
input is true. The next comparison test uses the next input
below and causes a jump to the label assigned to DEST1, if
the comparison is true, The remaining comparisons are
processed similarly and if none of the comparisons are true,
then a jump to the label assigned to the ELSE output occurs.
1
The K input and comparison inputs (==, <>, <, <=, >, >=) must be the same data type.
S7-1200 Programmable controller
304
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
Adding inputs, deleting inputs, and specifying comparison types
When the LAD or FBD SWITCH box is first placed in your program there are two comparison
inputs. You can assign comparison types and add inputs/jump destinations, as shown below.
Click a comparison operator inside the box and select a new operator
from the drop-down list.
Click the create icon inside the box (to the left of the last DEST parameter) to add new comparison-destination parameters.
• Right-click on an input stub and select the "Insert input" command.
• Right-click on an input stub and select the "Delete" command.
Table 8- 135 SWITCH box data type selection and allowed comparison operations
Data type
Comparison
Operator syntax
Byte, Word, DWord
Equal
==
Not equal
<>
Equal
==
Not equal
<>
Greater than or equal
>=
Less than or equal
<=
Greater than
>
Less than
<
SInt, Int, DInt, USInt, UInt,
UDInt, Real, LReal, Time, TOD,
Date
SWITCH box placement rules
● No LAD/FBD instruction connection in front of the compare input is allowed.
● There is no ENO output, so only one SWITCH instruction is allowed in a network and the
SWITCH instruction must be the last operation in a network.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
305
Basic instructions
8.8 Program control operations
8.8.4
RET (Return)
The optional RET instruction is used to terminate the execution of the current block. If and
only if there is power flow to the RET coil (LAD) or if the RET box input is true (FBD), then
program execution of the current block will end at that point and instructions beyond the RET
instruction will not be executed. If the current block is an OB, the "Return_Value" parameter
is ignored. If the current block is a FC or FB, the value of the "Return_Value" parameter is
passed back to the calling routine as the ENO value of the called box.
You are not required to use a RET instruction as the last instruction in a block; this is done
automatically for you. You can have multiple RET instructions within a single block.
For SCL, see the RETURN (Page 325) statement.
Table 8- 136 Return_Value (RET) execution control instruction
LAD
FBD
SCL
RETURN;
Description
Terminates the execution of the current block
Table 8- 137 Data types for the parameters
Parameter
Data type
Description
Return_Value
Bool
The "Return_value" parameter of the RET instruction is assigned to the ENO output
of the block call box in the calling block.
Sample steps for using the RET instruction inside an FC code block:
1. Create a new project and add an FC:
2. Edit the FC:
– Add instructions from the instruction tree.
– Add a RET instruction, including one of the following for the "Return_Value"
parameter:
TRUE, FALSE, or a memory location that specifies the required return value.
– Add more instructions.
3. Call the FC from MAIN [OB1].
The EN input on the FC box in the MAIN code block must be true to begin execution of the
FC.
The value specified by the RET instruction in the FC will be present on the ENO output of the
FC box in the MAIN code block following execution of the FC for which power flow to the
RET instruction is true.
S7-1200 Programmable controller
306
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.5
ENDIS_PW (Enable/disable CPU passwords)
Table 8- 138 ENDIS_PW instruction
LAD / FBD
SCL
ENDIS_PW(
req:=_bool_in_,
f_pwd:=_bool_in_,
full_pwd:=_bool_in_,
r_pwd:=_bool_in_,
hmi_pwd:=_bool_in_,
f_pwd_on=>_bool_out_,
full_pwd_on=>_bool_out_,
r_pwd_on=>_bool_out_,
hmi_pwd_on=>_bool_out_);
Description
The ENDIS_PW instruction can allow and
disallow client connections to a S7-1200
CPU, even when the client can provide the
correct password.
This instruction does not disallow Web
server passwords.
Table 8- 139 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
Perform function if REQ=1
F_PWD
IN
Bool
Fail-safe password: Allow (=1) or disallow (=0)
FULL_PWD
IN
Bool
Full access password: Allow (=1) or disallow (=0) full access password
R_PWD
IN
Bool
Read access password: Allow (=1) or disallow (=0)
HMI_PWD
IN
Bool
HMI password: Allow (=1) or disallow (=0)
F_PWD_ON
OUT
Bool
Fail-safe password status: Allowed (=1) or disallowed (=0)
FULL_PWD_ON
OUT
Bool
Full access password status: Allowed (=1) or disallowed (=0)
R_PWD_ON
OUT
Bool
Read only password status: Allowed (=1) or disallowed (=0)
HMI_PWD_ON
OUT
Bool
HMI password status: Allowed (=1) or disallowed (=0)
Ret_Val
OUT
Word
Function result
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
307
Basic instructions
8.8 Program control operations
Calling ENDIS_PW with REQ=1 disallows password types where the corresponding
password input parameter is FALSE. Each password type can be allowed or disallowed
independently. For example, if the fail-safe password is allowed and all other passwords
disallowed, then you can restrict CPU access to a small group of employees.
ENDIS_PW is executed synchronously in a program scan and the password output
parameters always show the current state of password allowance independent of the input
parameter REQ. All passwords that you set to allow must be changeable to
disallowed/allowed. Otherwise, an error is returned and all passwords are allowed that were
allowed before ENDIS_PW execution. This means that in a standard CPU (where the failsafe password is not configured) F_PWD must always be set to 1, to result in a return value
of 0. In this case, F_PWD_ON is always 1.
Note
• ENDIS_PW execution can block the access of HMI devices, if the HMI password is
disallowed.
• Client sessions that were authorized prior to ENDIS_PW execution remain unchanged by
ENDIS_PW execution.
After a power-up, CPU access is restricted by passwords previously defined in the regular
CPU protection configuration. The ability to disallow a valid password must be re-established
with a new ENDIS_PW execution. However, if ENDIS_PW is immediately executed and
necessary passwords are disallowed, then TIA portal access can be locked out. You can use
a timer instruction to delay ENDIS_PW execution and allow time to enter passwords, before
the passwords become disallowed.
Note
Restoring a CPU that locks out TIA portal communication
Refer to the "Recovery from a lost password (Page 151)" topic for details about how to erase
the internal load memory of a PLC using a memory card.
An operating mode change to STOP caused by errors, STP execution or STEP 7 does not
abolish the protection. The protection is valid until the CPU is power cycled. See the
following table for details.
Action
Operating mode
ENDIS_PW password control
After memory reset from
STEP 7
STOP
Active: Disallowed passwords
remain disallowed.
After powering on, or changing
a memory card
STOP
Off: No passwords are disallowed.
After ENDIS_PW execution in a
program cycle or startup OB
STARTUP, RUN
Active: Passwords are disallowed according to ENDIS_PW
parameters
After change of the operating
mode from RUN or STARTUP
to STOP through STP instruction, error, or STEP 7
STOP
Active: Disallowed passwords
remain disallowed
S7-1200 Programmable controller
308
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
Note
Password protect CPU access levels with strong passwords. Strong passwords are at least
ten characters in length, mix letters, numbers, and special characters, are not words that can
be found in a dictionary, and are not names or identifiers that can be derived from personal
information. Keep the password secret and change it frequently.
Table 8- 140 Condition codes
RET_VAL
Description
(W#16#...)
8.8.6
0000
No error
8090
The instruction is not supported.
80D0
The password for fail-safe is not configured.
80D1
The password for read/write access is not configured.
80D2
The password for read access is not configured.
80D3
The password for HMI access is not configured.
RE_TRIGR (Restart cycle monitoring time)
Table 8- 141 RE_TRIGR instruction
LAD / FBD
SCL
RE_TRIGR();
Description
RE_TRIGR (Re-trigger scan time watchdog) is used to extend the maximum
time allowed before the scan cycle watchdog timer generates an error.
Use the RE_TRIGR instruction to restart the scan cycle monitoring timer during a single scan
cycle. This has the effect of extending the allowed maximum scan cycle time by one
maximum cycle time period, from the last execution of the RE_TRIGR function.
Note
Prior to S7-1200 CPU firmware version 2.2, RE_TRIGR was restricted to execution from a
program cycle OB and could be used to extend the PLC scan time indefinitely. ENO =
FALSE and the watchdog timer is not reset when RE_TRIGR was executed from a start up
OB, an interrupt OB, or an error OB.
For firmware version 2.2 and later, RE_TRIGR can be executed from any OB (including start
up, interrupt, and error OBs). However, the PLC scan can only be extended by a maximum
of 10x the configured maximum cycle time.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
309
Basic instructions
8.8 Program control operations
Setting the PLC maximum cycle time
Configure the value for maximum scan cycle time in the Device configuration for "Cycle
time".
Table 8- 142 Cycle time values
Cycle time monitor
Minimum value
Maximum value
Default value
Maximum cycle time
1 ms
6000 ms
150 ms
Watchdog timeout
If the maximum scan cycle timer expires before the scan cycle has been completed, an error
is generated. If the user program includes a time error interrupt OB (OB 80), the CPU
executes the time error interrupt OB, which can include program logic to create a special
reaction.
If the user program does not include a time error interrupt OB, the first timeout condition is
ignored and the CPU remains in RUN mode. If a second maximum scan time timeout occurs
in the same program scan (2 times the maximum cycle time value), then an error is triggered
that causes a transition to STOP mode.
In STOP mode, your program execution stops while CPU system communications and
system diagnostics continue.
8.8.7
STP (Exit program)
Table 8- 143 STP instruction
LAD / FBD
SCL
STP();
Description
STP puts the CPU in STOP mode. When the CPU is in STOP mode, the
execution of your program and physical updates from the process image are
stopped.
For more information see: Configuring the outputs on a RUN-to-STOP transition (Page 116).
If EN = TRUE, then the CPU goes to STOP mode, the program execution stops, and the
ENO state is meaningless. Otherwise, EN = ENO = 0.
S7-1200 Programmable controller
310
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.8
GET_ERROR and GET_ERROR_ID (Get error and error ID locally) instructions
The get error instructions provide information about program block execution errors. If you
add a GET_ERROR or GET_ERROR_ID instruction to your code block, you can handle
program errors within your program block.
GET_ERROR
Table 8- 144 GET_ERROR instruction
LAD / FBD
SCL
GET_ERROR(_out_);
Description
Indicates that a local program block execution error has occurred
and fills a predefined error data structure with detailed error information.
Table 8- 145 Data types for the parameters
Parameter
Data type
Description
ERROR
ErrorStruct
Error data structure: You can rename the structure, but not the
members within the structure.
Table 8- 146 Elements of the ErrorStruct data structure
Structure components
Data type
Description
ERROR_ID
Word
Error ID
FLAGS
Byte
Shows if an error occurred during a block call.
REACTION
CODE_ADDRESS
BLOCK_TYPE
Byte
•
16#01: Error during a block call.
•
16#00: No error during a block call.
Default reaction:
•
0: Ignore (write error),
•
1: Continue with substitute value "0" (read error),
•
2: Skip instruction (system error)
CREF
Information about the address and type of block
Byte
Type of block where the error occurred:
•
1: OB
•
2: FC
•
3: FB
CB_NUMBER
UInt
Number of the code block
OFFSET
UDInt
Reference to the internal memory
Byte
Access mode: Depending on the type of access, the following information can be output:
MODE
Mode
(A)
(B)
(C)
(D)
(E)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
311
Basic instructions
8.8 Program control operations
Structure components
Data type
Description
0
1
Offset
2
3
Area
Location
Scope
Number
4
Area
5
Area
DB no.
Offset
Area
DB no.
Offset
Area
DB no.
Offset
6
PtrNo.
/Acc
7
PtrNo. /
Acc
Slot No. /
Scope
OPERAND_NUMBER
UInt
Operand number of the machine command
POINTER_NUMBER_
LOCATION
UInt
(A) Internal pointer
SLOT_NUMBER_SCOPE
UInt
(B) Storage area in internal memory
DATA_ADDRESS
NREF
Information about the address of an operand
Byte
(C) Memory area:
AREA
•
L: 16#40 – 4E, 86, 87, 8E, 8F, C0 – CE
•
I: 16#81
•
Q: 16#82
•
M: 16#83
•
DB: 16#84, 85, 8A, 8B
DB_NUMBER
UInt
(D) Number of the data block
OFFSET
UDInt
(E) Relative address of the operand
Offset
GET_ERROR_ID
Table 8- 147 GetErrorID instruction
LAD / FBD
SCL
GET_ERR_ID();
Description
Indicates that a program block execution error has occurred and reports
the ID (identifier code) of the error.
Table 8- 148 Data types for the parameters
Parameter
Data type
Description
ID
Word
Error identifier values for the ErrorStruct ERROR_ID member
S7-1200 Programmable controller
312
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
Table 8- 149 Error_ID values
ERROR_ID hexadecimal
ERROR_ID decimal
Program block execution error
0
0
No error
2520
9504
Corrupted string
2522
9506
Operand out of range read error
2523
9507
Operand out of range write error
2524
9508
Invalid area read error
2525
9509
Invalid area write error
2528
9512
Data alignment read error (incorrect bit alignment)
2529
9513
Data alignment write error (incorrect bit alignment)
252C
9516
Uninitialized pointer error
2530
9520
DB write protected
2533
9523
Invalid pointer used
2538
9528
Access error: DB does not exist
2539
9529
Access error: Wrong DB used
253A
9530
Global DB does not exist
253C
9532
Wrong version or FC does not exist
253D
9533
Instruction does not exist
253E
9534
Wrong version or FB does not exist
253F
9535
Instruction does not exist
2550
9552
Access error: DB does not exist
2575
9589
Program nesting depth error
2576
9590
Local data allocation error
2942
10562
Physical input point does not exist
2943
10563
Physical output point does not exist
Operation
By default, the CPU responds to a block execution error by logging an error in the
diagnostics buffer. However, if you place one or more GET_ERROR or GET_ERROR_ID
instructions within a code block, this block is now set to handle errors within the block. In this
case, the CPU does not log an error in the diagnostics buffer. Instead, the error information
is reported in the output of the GET_ERROR or GET_ERROR_ID instruction. You can read
the detailed error information with the GET_ERROR instruction, or read just the error
identifier with GET_ERROR_ID instruction. Normally the first error is the most important, with
the following errors only consequences of the first error.
The first execution of a GET_ERROR or GET_ERROR_ID instruction within a block returns
the first error detected during block execution. This error could have occurred anywhere
between the start of the block and the execution of either GET_ERROR or GET_ERROR_ID.
Subsequent executions of either GET_ERROR or GET_ERROR_ID return the first error
since the previous execution of GET_ERROR or GET_ERROR_ID. The history of errors is
not saved, and execution of either instruction will re-arm the PLC system to catch the next
error.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
313
Basic instructions
8.8 Program control operations
The ErrorStruct data type used by the GET_ERROR instruction can be added in the data
block editor and block interface editors, so your program logic can access these values.
Select ErrorStruct from the data type drop-down list to add this structure. You can create
multiple ErrorStruct elements by using unique names. The members of an ErrorStruct cannot
be renamed.
Error condition indicated by ENO
If EN = TRUE and GET_ERROR or GET_ERROR_ID executes, then:
● ENO = TRUE indicates a code block execution error occurred and error data is present
● ENO = FALSE indicates no code block execution error occurred
You can connect error reaction program logic to ENO which activates after an error occurs. If
an error exists, then the output parameter stores the error data where your program has
access to it.
GET_ERROR and GET_ERROR_ID can be used to send error information from the currently
executing block (called block) to a calling block. Place the instruction in the last network of
the called block program to report the final execution status of the called block.
8.8.9
RUNTIME (Measure program runtime)
Table 8- 150 RUNTIME instruction
LAD / FBD
SCL
Ret_Val := RUNTIME(
_lread_inout_);
Description
Measures the runtime of the entire program, individual blocks, or
command sequences.
If you want to measure the runtime of your entire program, call the instruction "Measure
program runtime" in OB 1. Measurement of the runtime is started with the first call and the
output RET_VAL returns the runtime of the program after the second call. The measured
runtime includes all CPU processes that can occur during the program execution, for
example, interruptions caused by higher-level events or communication. The instruction
"Measure program runtime" reads an internal counter of the CPU and write the value to the
IN-OUT parameter MEM. The instruction calculates the current program runtime according
to the internal counter frequency and writes it to output RET_VAL.
If you want to measure the runtime of individual blocks or individual command sequences,
you need three separate networks. Call the instruction "Measure program runtime" in an
individual network within your program. You set the starting point of the runtime
measurement with this first call of the instruction. Then you call the required program block
or the command sequence in the next network. In another network, call the "Measure
program runtime" instruction a second time and assign the same memory to the IN-OUT
parameter MEM as you did during the first call of the instruction. The "Measure program
runtime" instruction in the third network reads an internal CPU counter and calculates the
current runtime of the program block or the command sequence according to the internal
counter frequency and writes it to the output RET_VAL.
S7-1200 Programmable controller
314
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
The Measure program runtime" instruction uses an internal high-frequency counter to
calculate the time. If the counter overruns, the instruction returns values <= 0.0. Ignore these
runtime values.
Note
The CPU cannot exactly determine the runtime of a command sequence, because the
sequence of instructions within a command sequence changes during optimized compilation
of the program.
Table 8- 151 Data types for the parameters
Parameter
Data type
Description
MEM
LReal
Starting poing of the runtime measurement
RET_VAL
LReal
Measured runtime in seconds
Example: RUNTIME instruction
The following example shows the use of the RUNTIME instruction to measure the execution
time of a function block:
Network 1:
Network 2:
Network 3:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
315
Basic instructions
8.8 Program control operations
When the "Tag_1" operand in network 1 has the signal state "1", the RUNTIME instruction
executes. The starting point for the runtime measurement is set with the first call of the
instruction and buffered as reference for the second call of the instruction in the "Mem"
operand.
The function block FB1 executes in network 2.
When the FB1 program block completes and the "Tag_1" operand has the signal state "1",
the RUNTIME instruction in network 3 executes. The second call of the instruction calculates
the runtime of the program block and writes the result to the output RET_VAL_2.
8.8.10
SCL program control statements
8.8.10.1
Overview of SCL program control statements
Structured Control Language (SCL) provides three types of program control statements for
structuring your user program:
● Selective statements: A selective statement enables you to direct program execution into
alternative sequences of statements.
● Loops: You can control loop execution using iteration statements. An iteration statement
specifies which parts of a program should be iterated depending on certain conditions.
● Program jumps: A program jump means an immediate jump to a specified jump
destination and therefore to a different statement within the same block.
These program control statements use the syntax of the PASCAL programming language.
Table 8- 152 Types of SCL program control statements
Program control statement
Description
Selective
IF-THEN statement
(Page 317)
Enables you to direct program execution into one of two alternative
branches, depending on a condition being TRUE or FALSE
CASE statement
(Page 318)
Enables the selective execution into 1 of n alternative branches, based
on the value of a variable
FOR statement
(Page 320)
Repeats a sequence of statements for as long as the control variable
remains within the specified value range
WHILE-DO statement
(Page 321)
Repeats a sequence of statements while an execution condition continues to be satisfied
REPEAT-UNTIL statement (Page 322)
Repeats a sequence of statements until a terminate condition is met
CONTINUE statement
(Page 323)
Stops the execution of the current loop iteration
EXIT statement
(Page 324)
Exits a loop at any point regardless of whether the terminate condition
is satisfied or not
GOTO statement
(Page 325)
Causes the program to jump immediately to a specified label
RETURN statement
(Page 325)
Causes the program to exit the block currently being executed and to
return to the calling block
Loop
Program jump
S7-1200 Programmable controller
316
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.10.2
IF-THEN statement
The IF-THEN statement is a conditional statement that controls program flow by executing a
group of statements, based on the evaluation of a Bool value of a logical expression. You
can also use brackets to nest or structure the execution of multiple IF-THEN statements.
Table 8- 153 Elements of the IF-THEN statement
SCL
IF "condition" THEN
statement_A;
statement_B;
statement_C;
;
[ELSIF "condition-n" THEN
statement_N;
;]
[ELSE
statement_X;
;]
END_IF;
1
Description
If "condition" is TRUE or 1, then execute the following statements until encountering the END_IF statement.
If "condition" is FALSE or 0, then skip to END_IF statement (unless the
program includes optional ELSIF or ELSE statements).
The optional ELSEIF1 statement provides additional conditions to be evaluated. For example: If "condition" in the IF-THEN statement is FALSE, then
the program evaluates "condition-n". If "condition-n" is TRUE, then execute
"statement_N".
The optional ELSE statement provides statements to be executed when the
"condition" of the IF-THEN statement is FALSE.
The END_IF statement terminates the IF-THEN instruction.
You can include multiple ELSIF statements within one IF-THEN statement.
Table 8- 154 Variables for the IF-THEN statement
Variables
Description
"condition"
Required. The logical expression is either TRUE (1) or FALSE (0).
"statement_A"
Optional. One or more statements to be executed when "condition" is TRUE.
"condition-n"
Optional. The logical expression to be evaluated by the optional ELSIF statement.
"statement_N"
Optional. One or more statements to be executed when "condition-n" of the ELSIF statement is
TRUE.
"statement_X"
Optional. One or more statements to be executed when "condition" of the IF-THEN statement
is FALSE.
An IF statement is executed according to the following rules:
● The first sequence of statements whose logical expression = TRUE is executed. The
remaining sequences of statements are not executed.
● If no Boolean expression = TRUE, the sequence of statements introduced by ELSE is
executed (or no sequence of statements if the ELSE branch does not exist).
● Any number of ELSIF statements can exist.
Note
Using one or more ELSIF branches has the advantage that the logical expressions
following a valid expression are no longer evaluated in contrast to a sequence of IF
statements. The runtime of a program can therefore be reduced.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
317
Basic instructions
8.8 Program control operations
8.8.10.3
CASE statement
Table 8- 155 Elements of the CASE statement
SCL
CASE "Test_Value" OF
"ValueList": Statement[; Statement, ...]
"ValueList": Statement[; Statement, ...]
[ELSE
Else-statement[; Else-statement, ...]]
END_CASE;
Description
The CASE statement executes one of several
groups of statements, depending on the value
of an expression.
Table 8- 156 Parameters
Parameter
Description
"Test_Value"
Required. Any numeric expression of data type Int
"ValueList"
Required. A single value or a comma-separated list of values or ranges of values. (Use two
periods to define a range of values: 2..8) The following example illustrates the different variants of the value list:
1: Statement_A;
2, 4: Statement _B;
3, 5..7,9: Statement _C;
Statement
Required. One or more statements that are executed when "Test_Value" matches any value
in the value list
Else-statement
Optional. One or more statements that are executed if no match with a value of the "ValueList" stated matches
S7-1200 Programmable controller
318
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
The CASE statement is executed according to the following rules:
● The Test_value expression must return a value of the type Int.
● When a CASE statement is processed, the program checks whether the value of the
Test_value expression is contained within a specified list of values. If a match is found,
the statement component assigned to the list is executed.
● If no match is found, the program section following ELSE is executed or no statement is
executed if the ELSE branch does not exist.
Example: Nested CASE statements
CASE statements can be nested. Each nested case statement must have an associated
END_CASE statement.
CASE "var1" OF
ELSE
1 : #var2 := 'A';
2 : #var2 := 'B';
CASE "var3" OF
65..90: #var2 := 'UpperCase';
97..122: #var2 := 'LowerCase';
ELSE
#var2:= 'SpecialCharacter';
END_CASE;
END_CASE;
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
319
Basic instructions
8.8 Program control operations
8.8.10.4
FOR statement
Table 8- 157 Elements of the FOR statement
SCL
FOR "control_variable" := "begin" TO "end"
[BY "increment"] DO
statement;
;
END_FOR;
Description
A FOR statement is used to repeat a sequence of
statements as long as a control variable is within
the specified range of values. The definition of a
loop with FOR includes the specification of an
initial and an end value. Both values must be the
same type as the control variable.
You can nest FOR loops. The END_FOR statement refers to the last executed FOR instruction.
Table 8- 158 Parameters
Parameter
Description
"control_variable"
Required. An integer (Int or DInt) that serves as a loop counter
"begin"
Required. Simple expression that specifies the initial value of the control variables
"end"
Required. Simple expression that determines the final value of the control variables
"increment"
Optional. Amount by which a "control variable" is changed after each loop. The "increment"
has the same data type as "control variable". If the "increment" value is not specified, then
the value of the run tags will be increased by 1 after each loop. You cannot change "increment" during the execution of the FOR statement.
The FOR statement executes as follows:
● At the start of the loop, the control variable is set to the initial value (initial assignment)
and each time the loop iterates, it is incremented by the specified increment (positive
increment) or decremented (negative increment) until the final value is reached.
● Following each run through of the loop, the condition is checked (final value reached) to
establish whether or not it is satisfied. If the end condition is not satisfied, the sequence of
statements is executed again, otherwise the loop terminates and execution continues
with the statement immediately following the loop.
Rules for formulating FOR statements:
● The control variable may only be of the data type Int or DInt.
● You can omit the statement BY [increment]. If no increment is specified, it is automatically
assumed to be +1.
To end the loop regardless of the state of the "condition" expression, use the EXIT statement
(Page 324). The EXIT statement executes the statement immediately following the
END_FOR statement.
Use the CONTINUE statement (Page 323) to skip the subsequent statements of a FOR loop
and to continue the loop with the examination of whether the condition is met for termination.
S7-1200 Programmable controller
320
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.10.5
WHILE-DO statement
Table 8- 159 WHILE statement
SCL
WHILE "condition" DO
Statement;
Statement;
...;
END_WHILE;
Description
The WHILE statement performs a series of statements until a given condition is
TRUE.
You can nest WHILE loops. The END_WHILE statement refers to the last executed
WHILE instruction.
Table 8- 160 Parameters
Parameter
Description
"condition"
Required. A logical expression that evaluates to TRUE or FALSE. (A "null" condition is interpreted as FALSE.)
Statement
Optional. One or more statements that are executed until the condition evaluates to TRUE.
Note
The WHILE statement evaluates the state of "condition" before executing any of the
statements. To execute the statements at least one time regardless of the state of
"condition", use the REPEAT statement (Page 322).
The WHILE statement executes according to the following rules:
● Prior to each iteration of the loop body, the execution condition is evaluated.
● The loop body following DO iterates as long as the execution condition has the value
TRUE.
● Once the value FALSE occurs, the loop is skipped and the statement following the loop is
executed.
To end the loop regardless of the state of the "condition" expression, use the EXIT statement
(Page 324). The EXIT statement executes the statement immediately following the
END_WHILE statement.
Use the CONTINUE statement to skip the subsequent statements of a WHILE loop and to
continue the loop with the examination of whether the condition is met for termination.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
321
Basic instructions
8.8 Program control operations
8.8.10.6
REPEAT-UNTIL statement
Table 8- 161 REPEAT instruction
SCL
REPEAT
Statement;
;
UNTIL "condition"
END_REPEAT;
Description
The REPEAT statement executes a group of statements until a given condition is
TRUE.
You can nest REPEAT loops. The END_REPEAT statement always refers to the last
executed Repeat instruction.
Table 8- 162 Parameters
Parameter
Description
Statement
Optional. One or more statements that are executed until the condition is TRUE.
"condition"
Required. One or more expressions of the two following ways: A numeric expression or string
expression that evaluates to TRUE or FALSE. A "null" condition is interpreted as FALSE.
Note
Before evaluating the state of "condition", the REPEAT statement executes the statements
during the first iteration of the loop (even if "condition" is FALSE). To review the state of
"condition" before executing the statements, use the WHILE statement (Page 321).
To end the loop regardless of the state of the "condition" expression, use the EXIT statement
(Page 324). The EXIT statement executes the statement immediately following the
END_REPEAT statement.
Use the CONTINUE statement (Page 323) to skip the subsequent statements of a REPEAT
loop and to continue the loop with the examination of whether the condition is met for
termination.
S7-1200 Programmable controller
322
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.10.7
CONTINUE statement
Table 8- 163 CONTINUE statement
SCL
CONTINUE
Statement;
;
Description
The CONTINUE statement skips the subsequent statements of a program loop (FOR,
WHILE, REPEAT) and continues the loop with the examination of whether the condition is
met for termination. If this is not the case, the loop continues.
The CONTINUE statement executes according to the following rules:
● This statement immediately terminates execution of a loop body.
● Depending on whether the condition for repeating the loop is satisfied or not the body is
executed again or the iteration statement is exited and the statement immediately
following is executed.
● In a FOR statement, the control variable is incremented by the specified increment
immediately after a CONTINUE statement.
Use the CONTINUE statement only within a loop. In nested loops CONTINUE always refers
to the loop that includes it immediately. CONTINUE is typically used in conjunction with an IF
statement.
If the loop is to exit regardless of the termination test, use the EXIT statement.
Example: CONTINUE statement
The following example shows the use of the CONTINUE statement to avoid a division-by-0
error when calculating the percentage of a value:
FOR i := 0 TO 10 DO
IF value[i] = 0 THEN CONTINUE; END_IF;
p := part / value[i] * 100;
s := INT_TO_STRING(p);
percent := CONCAT(IN1:=s, IN2:="%");
END_FOR;
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
323
Basic instructions
8.8 Program control operations
8.8.10.8
EXIT statement
Table 8- 164 EXIT instruction
SCL
EXIT;
Description
An EXIT statement is used to exit a loop (FOR, WHILE or REPEAT) at any point, regardless of whether
the terminate condition is satisfied.
The EXIT statement executes according to the following rules:
● This statement causes the repetition statement immediately surrounding the exit
statement to be exited immediately.
● Execution of the program is continued after the end of the loop (for example after
END_FOR).
Use the EXIT statement within a loop. In nested loops, the EXIT statement returns the
processing to the next higher nesting level.
Example: EXIT statement
FOR i := 0 TO 10 DO
CASE value[i, 0] OF
1..10: value [i, 1]:="A";
11..40: value [i, 1]:="B";
41..100: value [i, 1]:="C";
ELSE
EXIT;
END_CASE;
END_FOR;
S7-1200 Programmable controller
324
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.8 Program control operations
8.8.10.9
GOTO statement
Table 8- 165 GOTO statement
SCL
GOTO JumpLabel;
Statement;
... ;
JumpLabel: Statement;
Description
The GOTO statement skips over statements by jumping to a label in the same
block.
The jump label ("JumpLabel") and the GOTO statement must be in the same block.
The name of a jump label can only be assigned once within a block. Each jump
label can be the target of several GOTO statements.
It is not possible to jump to a loop section (FOR, WHILE or REPEAT). It is possible to jump
from within a loop.
Example: GOTO statement
In the following example: Depending on the value of the "Tag_value" operand, the execution
of the program resumes at the point defined by the corresponding jump label. If "Tag_value"
equals 2, the program execution resumes at the jump label "MyLabel2" and skips
"MyLabel1".
CASE "Tag_value" OF
1 : GOTO MyLabel1;
2 : GOTO MyLabel2;
ELSE GOTO MyLabel3;
END_CASE;
MyLabel1: "Tag_1" := 1;
MyLabel2: "Tag_2" := 1;
MyLabel3: "Tag_4" := 1;
8.8.10.10
RETURN statement
Table 8- 166 RETURN instruction
SCL
RETURN;
Description
The Return instruction exits the code block being executed without conditions. Program execution returns to the calling block or to the operating system (when exiting an OB).
Example: RETURN instruction:
IF "Error" <> 0 THEN
RETURN;
END_IF;
Note
After executing the last instruction, the code block automatically returns to the calling block.
Do not insert a RETURN instruction at the end of the code block.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
325
Basic instructions
8.9 Word logic operations
8.9
Word logic operations
8.9.1
AND, OR, and XOR logic operation instructions
Table 8- 167 AND, OR, and XOR logic operation instructions
LAD / FBD
SCL
out := in1 AND in2;
Description
out := in1 OR in2;
OR: Logical OR
out := in1 XOR in2;
1
AND: Logical AND
XOR: Logical EXCLUSIVE OR
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
To add an input, click the "Create" icon or right-click on an input stub for one of the
existing IN parameters and select the "Insert input" command.
To remove an input, right-click on an input stub for one of the existing IN parameters (when
there are more than the original two inputs) and select the "Delete" command.
Table 8- 168 Data types for the parameters
1
Parameter
Data type
Description
IN1, IN2
Byte, Word, DWord
Logical inputs
OUT
Byte, Word, DWord
Logical output
The data type selection sets parameters IN1, IN2, and OUT to the same data type.
The corresponding bit values of IN1 and IN2 are combined to produce a binary logic result at
parameter OUT. ENO is always TRUE following the execution of these instructions.
S7-1200 Programmable controller
326
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.9 Word logic operations
8.9.2
INV (Create ones complement)
Table 8- 169 INV instruction
LAD / FBD
SCL
Not available
Description
Calculates the binary one's complement of the parameter IN. The one's
complement is formed by inverting each bit value of the IN parameter
(changing each 0 to 1 and each 1 to 0). ENO is always TRUE following
the execution of this instruction.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 170 Data types for the parameters
Parameter
Data type
Description
IN
SInt, Int, DInt, USInt, UInt, UDInt, Byte, Word, DWord
Data element to invert
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Byte, Word, DWord
Inverted output
8.9.3
DECO (Decode) and ENCO (Encode) instructions
Table 8- 171 ENCO and DECO instruction
LAD / FBD
SCL
Description
out := ENCO(_in_);
Encodes a bit pattern to a binary number
out := DECO(_in_);
Decodes a binary number to a bit pattern
The ENCO instruction converts parameter IN to the binary number
corresponding to the bit position of the least-significant set bit of
parameter IN and returns the result to parameter OUT. If parameter IN is either 0000 0001 or 0000 0000, then a value of 0 is returned to parameter OUT. If the parameter IN value is 0000 0000,
then ENO is set to FALSE.
The DECO instruction decodes a binary number from parameter
IN, by setting the corresponding bit position in parameter OUT to
a 1 (all other bits are set to 0). ENO is always TRUE following
execution of the DECO instruction.
Note: The default data type for the DECO instruction is DWORD.
In SCL, change the instruction name to DECO_BYTE or
DECO_WORD to decode a byte or word value, and assign to a
byte or word tag or address.
1
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
327
Basic instructions
8.9 Word logic operations
Table 8- 172 Data types for the parameters
Parameter
Data type
Description
IN
ENCO: Byte, Word, DWord
ENCO: Bit pattern to encode
DECO: UInt
DECO: Value to decode
ENCO: Int
ENCO: Encoded value
DECO: Byte, Word, DWord
DECO: Decoded bit pattern
OUT
Table 8- 173 ENO status
ENO
Condition
Result (OUT)
1
No error
Valid bit number
0
IN is zero
OUT is set to zero
The DECO parameter OUT data type selection of a Byte, Word, or DWord restricts the
useful range of parameter IN. If the value of parameter IN exceeds the useful range, then a
modulo operation is performed to extract the least significant bits shown below.
DECO parameter IN range:
● 3 bits (values 0-7) IN are used to set 1 bit position in a Byte OUT
● 4-bits (values 0-15) IN are used to set 1 bit position in a Word OUT
● 5 bits (values 0-31) IN are used to set 1 bit position in a DWord OUT
Table 8- 174 Examples
DECO IN value
DECO OUT value ( Decode single bit position)
Byte OUT
Min. IN
0
00000001
8 bits
Max. IN
7
10000000
Word OUT
Min. IN
0
0000000000000001
16 bits
Max. IN
15
1000000000000000
DWord OUT
Min. IN
0
00000000000000000000000000000001
32 bits
Max. IN
31
10000000000000000000000000000000
S7-1200 Programmable controller
328
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.9 Word logic operations
8.9.4
SEL (Select), MUX (Multiplex), and DEMUX (Demultiplex) instructions
Table 8- 175 SEL (select) instruction
LAD / FBD
SCL
out := SEL(
g:=_bool_in,
in0:-_variant_in,
in1:=_variant_in);
Description
SEL assigns one of two input values to parameter OUT, depending
on the parameter G value.
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
1
Table 8- 176 Data types for the SEL instruction
1
Parameter
Data type 1
Description
G
Bool
•
0 selects IN0
•
1 selects IN1
IN0, IN1
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord,
Time, Date, TOD, Char, WChar
Inputs
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord,
Time, Date, TOD, Char, WChar
Output
Input variables and the output variable must be of the same data type.
Condition codes: ENO is always TRUE following execution of the SEL instruction.
Table 8- 177 MUX (multiplex) instruction
LAD / FBD
SCL
out := MUX(
k:=_unit_in,
in1:=variant_in,
in2:=variant_in,
Description
MUX copies one of many input values to parameter OUT, depending
on the parameter K value. If the parameter K value exceeds (INn - 1),
then the parameter ELSE value is copied to parameter OUT.
[...in32:=variant_in,]
inelse:=variant_in);
1
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
329
Basic instructions
8.9 Word logic operations
To add an input, click the "Create" icon or right-click on an input stub for one of
the existing IN parameters and select the "Insert input" command.
To remove an input, right-click on an input stub for one of the existing IN parameters (when
there are more than the original two inputs) and select the "Delete" command.
Table 8- 178 Data types for the MUX instruction
1
Parameter
Data type
Description
K
UInt
•
0 selects IN1
•
1 selects IN2
•
n selects INn
IN0, IN1, .. INn
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord,
Time, Date, TOD, Char, WChar
Inputs
ELSE
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord,
Time, Date, TOD, Char, WChar
Input substitute value (optional)
OUT
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word, DWord,
Time, Date, TOD, Char, WChar
Output
Input variables and the output variable must be of the same data type.
Table 8- 179 DEMUX (Demultiplex) instruction
LAD / FBD
SCL
DEMUX(
k:=_unit_in,
in:=variant_in,
out1:=variant_in,
out2:=variant_in,
Description
DEMUX copies the value of the location assigned to parameter IN to
one of many outputs. The value of the K parameter selects which
output selected as the destination of the IN value. If the value of K is
greater than the number (OUTn - 1) then the IN value is copied to
location assigned to the ELSE parameter.
[...out32:=variant_in,]
outelse:=variant_in);
1
For LAD and FBD: Click the "???" and select a data type from the drop-down menu.
To add an output, click the "Create" icon or right-click on an output stub for one
of the existing OUT parameters and select the "Insert output" command.
To remove an output, right-click on an output stub for one of the existing OUT parameters
(when there are more than the original two outputs) and select the "Delete" command.
S7-1200 Programmable controller
330
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.9 Word logic operations
Table 8- 180 Data types for the DEMUX instruction
Parameter
Data type 1
Description
K
UInt
Selector value:
•
0 selects OUT1
•
1 selects OUT2
•
n selects OUTn
IN
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, Char, WChar
Input
OUT0, OUT1, ..
OUTn
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, Char, WChar
Outputs
ELSE
SInt, Int, DInt, USInt, UInt, UDInt, Real, LReal, Byte, Word,
DWord, Time, Date, TOD, Char, WChar
Substitute output when K is greater than
(OUTn - 1)
The input variable and the output variables must be of the same data type.
1
Table 8- 181 ENO status for the MUX and DEMUX instructions
ENO
Condition
Result OUT
1
No error
MUX: Selected IN value is copied to
OUT
DEMUX: IN value is copied to selected
OUT
0
MUX: K is greater than the number of inputs -1
DEMUX: K is greater than the number of outputs -1
•
No ELSE provided: OUT is unchanged,
•
ELSE provided, ELSE value assigned
to OUT
•
No ELSE provided: outputs are unchanged,
•
ELSE provided, IN value copied to
ELSE
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
331
Basic instructions
8.10 Shift and rotate
8.10
Shift and rotate
8.10.1
SHR (Shift right) and SHL (Shift left) instructions
Table 8- 182 SHR and SHL instructions
LAD / FBD
SCL
out := SHR(
in:=_variant_in_,
n:=_uint_in);
out := SHL(
in:=_variant_in_,
n:=_uint_in);
Description
Use the shift instructions (SHL and SHR) to shift the bit pattern of
parameter IN. The result is assigned to parameter OUT. Parameter N specifies the number of bit positions shifted:
•
SHR: Shift bit pattern right
•
SHL: Shift bit pattern left
For LAD and FBD: Click the "???" and select the data types from the drop-down menu.
1
Table 8- 183 Data types for the parameters
Parameter
Data type
Description
IN
Integers
Bit pattern to shift
N
USInt, UDint
Number of bit positions to shift
OUT
Integers
Bit pattern after shift operation
● For N=0, no shift occurs. The IN value is assigned to OUT.
● Zeros are shifted into the bit positions emptied by the shift operation.
● If the number of positions to shift (N) exceeds the number of bits in the target value (8 for
Byte, 16 for Word, 32 for DWord), then all original bit values will be shifted out and
replaced with zeros (zero is assigned to OUT).
● ENO is always TRUE for the shift operations.
Table 8- 184 Example: SHL for Word data
Shift the bits of a Word to the left by inserting zeroes from the right (N = 1)
IN
1110 0010 1010 1101
OUT value before first shift:
1110 0010 1010 1101
After first shift left:
1100 0101 0101 1010
After second shift left:
1000 1010 1011 0100
After third shift left:
0001 0101 0110 1000
S7-1200 Programmable controller
332
System Manual, V4.2, 09/2016, A5E02486680-AK
Basic instructions
8.10 Shift and rotate
8.10.2
ROR (Rotate right) and ROL (Rotate left) instructions
Table 8- 185 ROR and ROL instructions
LAD / FBD
SCL
out := ROL(
in:=_variant_in_,
n:=_uint_in);
out := ROR(
in:=_variant_in_,
n:=_uint_in);
Description
Use the rotate instructions (ROR and ROL) to rotate the bit pattern of
parameter IN. The result is assigned to parameter OUT. Parameter N
defines the number of bit positions rotated.
•
ROR: Rotate bit pattern right
•
ROL: Rotate bit pattern left
For LAD and FBD: Click the "???" and select the data types from the drop-down menu.
1
Table 8- 186 Data types for the parameters
Parameter
Data type
Description
IN
Integers
Bit pattern to rotate
N
USInt, UDint
Number of bit positions to rotate
OUT
Integers
Bit pattern after rotate operation
● For N=0, no rotate occurs. The IN value is assigned to OUT.
● Bit data rotated out one side of the target value is rotated into the other side of the target
value, so no original bit values are lost.
● If the number of bit positions to rotate (N) exceeds the number of bits in the target value
(8 for Byte, 16 for Word, 32 for DWord), then the rotation is still performed.
● ENO is always TRUE following execution of the rotate instructions.
Table 8- 187 Example: ROR for Word data
Rotate bits out the right -side into the left -side (N = 1)
IN
0100 0000 0000 0001
OUT value before first rotate:
0100 0000 0000 0001
After first rotate right:
1010 0000 0000 0000
After second rotate right:
0101 0000 0000 0000
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
333
Basic instructions
8.10 Shift and rotate
S7-1200 Programmable controller
334
System Manual, V4.2, 09/2016, A5E02486680-AK
9
Extended instructions
9.1
Date, time-of-day, and clock functions
9.1.1
Date and time-of-day instructions
Use the date and time instructions for calendar and time calculations.
● T_CONV converts a value to or from (date and time data types) and (byte, word, and
dword size data types)
● T_ADD adds Time and DTL values: (Time + Time = Time) or (DTL + Time = DTL)
● T_SUB subtracts Time and DTL values: (Time - Time = Time) or (DTL - Time = DTL)
● T_DIFF provides the difference between two DTL values as a Time value: DTL - DTL =
Time
● T_COMBINE combines a Date value and a Time_and_Date value to create a DTL value
For information about the format of DTL and Time data, refer to the section on the Time and
Date data types (Page 128).
Table 9- 1
LAD / FBD
T_CONV (Convert times and extract) instruction
SCL example
out := DINT_TO_TIME(
in:=_variant_in);
Description
T_CONV converts a value to or from (date and time data types) and
(byte, word, and dword size data types).
out := TIME_TO_DINT(
in:=_variant_in);
1
For LAD and FBD boxes: Click "???" and select the source/target data types from the drop-down menu.
2
For SCL: Drag T_CONV from instruction tree and drop into the program editor, then select the source/target data types.
Table 9- 2
Valid data types for T_CONV conversions
Data type IN (or OUT)
Data types OUT (or IN)
TIME (milliseconds)
DInt, Int, SInt, UDInt, UInt, USInt, TOD
SCL only: Byte, Word, Dword
DATE (number of days since Jan. 1 1990)
DInt, Int, SInt, UDInt, UInt, USInt, DTL
SCL only: Byte, Word, Dword
TOD (milliseconds since midnight- 24:00:00.000)
DInt, Int, SInt, UDInt, UInt, USInt, TIME, DTL
SCL only: Byte, Word, Dword
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
335
Extended instructions
9.1 Date, time-of-day, and clock functions
Note
Using T_CONV to convert a larger data size to a smaller data size
Data values can be truncated when you convert a larger data type with more bytes to a
smaller data type with less bytes. If this error occurs, then ENO is set to 0.
Conversion to/from DTL data type
DTL (Date and Time Long) contains year, month, date, and time data. DTL data can be
converted to/from DATE and TOD data types.
However, DTL conversion with DATE data only affects the year, month, and day values. DTL
conversion with TOD data only affects the hour, minutes, and seconds values.
When T_CONV converts to DTL, the unaffected data elements in the DTL format are left
unchanged.
Table 9- 3
LAD / FBD
T_ADD (Add times) and T_SUB (Subtract times) instructions
SCL
out := T_ADD(
in1:=_variant_in,
in2:=_time_in);
out := T_SUB(
in1:=_variant_in,
in2:=_time_in);
1
T_ADD adds the input IN1 value (DTL or Time data types) with the
input IN2 Time value. Parameter OUT provides the DTL or Time value
result. Two data type operations are possible:
•
Time + Time = Time
•
DTL + Time = DTL
T_SUB subtracts the IN2 Time value from IN1 (DTL or Time value).
Parameter OUT provides the difference value as a DTL or Time data
type. Two data type operations are possible.
•
Time - Time = Time
•
DTL - Time = DTL
For LAD and FBD: Click the "???" and select the data types from the drop-down menu.
Table 9- 4
1
Description
Data types for the T_ADD and T_SUB parameters
Parameter and type
Data type
Description
IN11
IN
DTL, Time
DTL or Time value
IN2
IN
Time
Time value to add or subtract
OUT
OUT
DTL, Time
DTL or Time sum or difference
Select the IN1 data type from the drop-down list available below the instruction name. The IN1 data type selection also
sets the data type of parameter OUT.
S7-1200 Programmable controller
336
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.1 Date, time-of-day, and clock functions
Table 9- 5
T_DIFF (Time difference) instruction
LAD / FBD
Table 9- 6
SCL
out := T_DIFF(
in1:=_DTL_in,
in2:=_DTL_in);
Description
T_DIFF subtracts the DTL value (IN2) from the DTL value (IN1). Parameter OUT provides the difference value as a Time data type.
•
DTL - DTL = Time
Data types for the T_DIFF parameters
Parameter and type
Data type
Description
IN1
IN
DTL
DTL value
IN2
IN
DTL
DTL value to subtract
OUT
OUT
Time
Time difference
Condition codes: ENO = 1 means no error occurred. ENO = 0 and parameter OUT = 0
errors:
● Invalid DTL value
● Invalid Time value
Table 9- 7
T_COMBINE (Combine times) instruction
LAD / FBD
1
SCL
out :=
CONCAT_DATE_TOD(
In1 := _date_in,
In2 := _tod_in);
Description
T_COMBINE combines a Date value and a Time_of_Day
value to create a DTL value.
Note that the T_COMBINE instruction in the Extended Instructions equates to the CONCAT_DATE_TOD function in
SCL.
Table 9- 8
Data types for the T_COMBINE parameters
Parameter and type
Data type
Description
IN1
IN
Date
Date value to be combined must be between DATE#199001-01 and DATE#2089-12-31
IN2
IN
Time_of_Day
Time_of_Day values to be combined
OUT
OUT
DTL
DTL value
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
337
Extended instructions
9.1 Date, time-of-day, and clock functions
9.1.2
Clock functions
WARNING
If an attacker can access your networks through Network Time Protocol (NTP)
synchronization, the attacker can possibly take limited control of your process by shifting
the CPU system time.
The NTP client feature of the S7-1200 CPU is disabled by default, and, when enabled, only
allows configured IP addresses to act as an NTP server. The CPU disables this feature by
default, and you must configure this feature to allow remotely-controlled CPU system time
corrections.
The S7-1200 CPU supports "time of day" interrupts and clock instructions that depend upon
accurate CPU system time. If you configure NTP and accept time synchronization from a
server, you must ensure that the server is a trusted source. Failure to do so can cause a
security breach that allows an unknown user to take limited control of your process by
shifting the CPU system time.
For security information and recommendations, please see our "Operational Guidelines for
Industrial Security" (http://www.industry.siemens.com/topics/global/en/industrialsecurity/Documents/operational_guidelines_industrial_security_en.pdf) on the Siemens
Service and Support site.
S7-1200 Programmable controller
338
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.1 Date, time-of-day, and clock functions
Use the clock instructions to set and read the CPU system clock. The data type DTL
(Page 128) is used to provide date and time values.
Table 9- 9
System time instructions
LAD / FBD
SCL
ret_val :=
WR_SYS_T(
in:=_DTL_in_);
ret_val :=
RD_SYS_T(
out=>_DTL_out);
ret_val :=
RD_LOC_T(
out=>_DTL_out);
Description
WR_SYS_T (Set time-of-day) sets the CPU time of day clock
with a DTL value at parameter IN. This time value does not include local time zone or daylight saving time offsets.
RD_SYS_T (Read time-of-day) reads the current system time
from the CPU. This time value does not include local time zone
or daylight saving time offsets.
RD_LOC_T (Read local time) provides the current local time of
the CPU as a DTL data type. This time value reflects the local
time zone adjusted appropriately for daylight saving time (if configured).
ret_val :=
WR_LOC_T(
WR_LOC_T (Write local time) sets the date and time of the CPU
clock. You assign the date and time information as local time at
LOCTIME with DTL data type. The instruction uses the
LOCTIME:=DTL_in_, "TimeTransformationRule (Page 342)" DB structure to calculate
the system time. The granularity of the time information for local
DST:_in_;
time and system time is product-specific and is at least one millisecond. Input values at the LOCTIME parameter which are less
than those supported by the CPU are rounded up during system
time calculation.
Note: You must use the CPU device configuration to set the
"Time of day" properties (time zone, DST activation, DST start,
and DST stop). Otherwise, WR_LOC_T cannot interpret the DST
time change.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
339
Extended instructions
9.1 Date, time-of-day, and clock functions
Table 9- 10
Data types for the parameters
Parameter and type
Data type
Description
IN
IN
DTL
Time of day to set in the CPU system clock
OUT
OUT
DTL
RD_SYS_T: Current CPU system time
RD_LOC_T: Current local time, including any adjustment for
daylight saving time, if configured
LOCTIME
IN
DTL
WR_LOC_T: Local time
DST
IN
BOOL
WR_LOC_T: Daylight Saving Time only evaluated during the
"double hour" when the clocks change to daylight saving time.
RET_VAL
OUT
Int
•
TRUE = daylight saving time (first hour)
•
FALSE = standard time (second hour)
Execution condition code
● The local time is calculated by using the time zone and daylight saving time offsets that
you set in the device configuration general tab "Time of day" parameters.
● Time zone configuration is an offset to UTC or GMT time.
● Daylight saving time configuration specifies the month, week, day, and hour when
daylight saving time begins.
● Standard time configuration also specifies the month, week, day, and hour when standard
time begins.
● The time zone offset is always applied to the system time value. The daylight saving time
offset is only applied when daylight saving time is in effect.
Note
Daylight saving and standard start time configuration
The "Time of day" properties for "Start for daylight saving time" of the CPU device
configuration must be your local time.
S7-1200 Programmable controller
340
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.1 Date, time-of-day, and clock functions
Condition codes: ENO = 1 means no error occurred. ENO = 0 means an execution error
occurred, and a condition code is provided at the RET_VAL output.
RET_VAL (W#16#....) Description
0000
The current local time is in standard time.
0001
Daylight saving time has been configured, and the current local time is in daylight saving time.
8080
Local time not available or LOCTIME value is invalid.
8081
Illegal year value or time value assigned by the LOCTIME parameter is invalid
8082
Illegal month value (byte 2 in DTL format)
8083
Illegal day value (byte 3 in DTL format)
8084
Illegal hour value (byte 5 in DTL format)
8085
Illegal minute value (byte 6 in DTL format)
8086
Illegal second value (byte 7 in DTL format)
8087
Illegal nanosecond value (bytes 8 to 11 in DTL format)
8089
Time value does not exist (hour already passed upon changeover to daylight saving time)
80B0
The real-time clock has failed
80B1
The "TimeTransformationRule" structure has not been defined.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
341
Extended instructions
9.1 Date, time-of-day, and clock functions
9.1.3
TimeTransformationRule data structure
Description
The changeover rules for standard and daylight saving time are defined in the
TimeTransformationRule structure. The structure is as follows:
Name
Data type
TimeTransformationRule
STRUCT
Bias
INT
Description
Time difference between local time and UTC [minutes]
Range: -1439 to 1439
DaylightBias
INT
Time difference between daylight saving and standard time [minutes]
DaylightStartMonth
USINT
Month of conversion to daylight saving time
DaylightStartWeek
USINT
Range: 0 to 60
Range: 1 to 12
Week of conversion to daylight saving time
1 = First occurrence of the weekday in the month, ...,
5 = Last occurrence of the weekday in the month
DaylightStartWeekday
USINT
Weekday of daylight saving time changeover:
1 = Sunday
DaylightStartHour
USINT
Hour of daylight saving time changeover:
Range: 0 to 23
DaylightStartMinute
USINT
Minute of daylight saving time changeover
StandardStartMonth
USINT
Month of conversion to standard time
StandardStartWeek
USINT
Week of conversion to standard time
Range: 0 to 59
Range: 1 to 12
1 = First occurrence of the weekday in the month, ...,
5 = Last occurrence of the weekday in the month
StandardStartWeekday
USINT
Weekday of standard time changeover:
1 = Sunday
StandardStartHour
USINT
Hour of standard time changeover
StandardStartMinute
USINT
Minute of standard time changeover
TimeZoneName
STRING[80]
Name of time zone: "(GMT+01:00) Amsterdam, Berlin, Bern, Rome,
Stockholm, Vienna"
Range: 0 to 23
Range: 0 to 59
S7-1200 Programmable controller
342
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.1 Date, time-of-day, and clock functions
9.1.4
Table 9- 11
SET_TIMEZONE (Set timezone)
SET_TIMEZONE instruction
LAD / FBD
SCL
"SET_TIMEZONE_DB"(
REQ:=_bool_in,
Timezone:=_struct_in,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_);
Description
Sets the local time zone and daylight saving parameters that are used to transform
the CPU system time to local time.
In the SCL example, "SET_TIMEZONE_DB" is the name of the instance DB.
1
Table 9- 12
Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
REQ=1: execute function
Timezone
IN
TimeTransformationRule
Rules for the transformation from system time to
local time
DONE
OUT
Bool
Function complete
BUSY
OUT
Bool
Function busy
ERROR
OUT
Bool
Error detected
STATUS
OUT
Word
Function result / error message
To manually configure the time zone parameters for the CPU, use the "Time of day"
properties of the "General" tab of the device configuration.
Use the SET_TIMEZONE instruction to set the local time configuration. The parameters of
the "TimeTransformationRule (Page 342)" structure assign the local time zone and timing for
automatic switching between standard time and daylight saving time.
Condition codes: ENO = 1 means no error occurred. ENO = 0 means an execution error
occurred, and a condition code is provided at the STATUS output.
STATUS
(W#16#....)
Description
0
No error
7000
No job processing active
7001
Start of job processing. Parameter BUSY = 1, DONE = 0
7002
Intermediate call (REQ irrelevant): Instruction already active; BUSY has the value "1".
808x
Error at x-th component: For example 8084 indicates that DaylightStartWeekif is not a value from 1to 5.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
343
Extended instructions
9.1 Date, time-of-day, and clock functions
9.1.5
Table 9- 13
RTM (Runtime meters)
RTM instruction
LAD / FBD
Table 9- 14
SCL
RTM(NR:=_uint_in_,
MODE:=_byte_in_,
PV:=_dint_in_,
CQ=>_bool_out_,
CV=>_dint_out_);
Description
The RTM (Runtime Meters) instruction can set, start, stop, and
read the runtime hour meters in the CPU.
Data types for the parameters
Parameter and type
Data type
Description
NR
IN
UInt
Runtime meter number: (possible values: 0..9)
MODE
IN
Byte
RTM Execution mode number:
•
0 = Fetch values (the status is then written to CQ and the
current value to CV)
•
1 = Start (at the last counter value)
•
2 = Stop
•
4 = Set (to the value specified in PV)
•
5 = Set (to the value specified in PV) and then start
•
6 = Set (to the value specified in PV) and then stop
•
7 = Save all RTM values in the CPU to the MC (memory
card)
PV
IN
DInt
Preset hours value for the specified runtime meter
RET_VAL
OUT
Int
Function result / error message
CQ
OUT
Bool
Runtime meter status (1 = running)
CV
OUT
DInt
Current runtime hours value for the specified meter
The CPU operates up to 10 runtime hour meters to track the runtime hours of critical control
subsystems. You must start the individual hour meters with one RTM execution for each
timer. All runtime hour meters are stopped when the CPU makes a run-to-stop transition.
You can also stop individual timers with RTM execution mode 2.
When a CPU makes a stop-to-run transition, you must restart the hour timers with one RTM
execution for each timer that is started. After a runtime meter value is greater than
2147483647 hours, counting stops and the "Overflow" error is sent. You must execute the
RTM instruction once for each timer to reset or modify the timer.
A CPU power failure or power cycle causes a power-down process that saves the current
runtime meter values in retentive memory. Upon CPU power-up, the stored runtime meter
values are reloaded to the timers and the previous runtime hour totals are not lost. The
runtime meters must be restarted to accumulate additional runtime.
S7-1200 Programmable controller
344
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.1 Date, time-of-day, and clock functions
Your program can also use RTM execution mode 7 to save the runtime meter values in a
memory card. The states of all timers at the instant RTM mode 7 is executed are stored in
the memory card. These stored values can become incorrect over time as the hour timers
are started and stopped during a program run session. You must periodically update the
memory card values to capture important runtime events. The advantage that you get from
storing the RTM values in the memory card is that you can insert the memory card in a
substitute CPU where your program and saved RTM values will be available. If you did not
save the RTM values in the memory card, then the timer values would be lost (in a substitute
CPU).
Note
Avoid excessive program calls for memory card write operations
Minimize flash memory card write operations to extend the life of the memory card.
Table 9- 15
Condition codes
RET_VAL (W#16#....)
Description
0
No error
8080
Incorrect runtime meter number
8081
A negative value was passed to the parameter PV
8082
Overflow of the operating hours counter
8091
The input parameter MODE contains an illegal value
80B1
Value cannot be saved to MC (MODE=7)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
345
Extended instructions
9.2 String and character
9.2
String and character
9.2.1
String data overview
String data type
String data is stored as a 2-byte header followed by up to 254 character bytes of ASCII
character codes. A String header contains two lengths. The first byte is the maximum length
that is given in square brackets when you initialize a string, or 254 by default. The second
header byte is the current length that is the number of valid characters in the string. The
current length must be smaller than or equal to the maximum length. The number of stored
bytes occupied by the String format is 2 bytes greater than the maximum length.
Initialize your String data
String input and output data must be initialized as valid strings in memory, before execution
of any string instructions.
Valid String data
A valid string has a maximum length that must be greater than zero but less than 255. The
current length must be less than or equal to the maximum length.
Strings cannot be assigned to I or Q memory areas.
For more information see: Format of the String data type (Page 130).
9.2.2
S_MOVE (Move character string)
Table 9- 16
String move instruction
LAD / FBD
SCL
out := in;
Description
Copy the source IN string to the OUT location. S_MOVE execution does not affect
the contents of the source string.
Table 9- 17
Data types for the parameters
Parameter
Data type
Description
IN
String
Source string
OUT
String
Target address
If the actual length of the string at the input IN exceeds the maximum length of a string
stored at output OUT, then the part of the IN string which can fit in the OUT string is copied.
S7-1200 Programmable controller
346
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.3
String conversion instructions
9.2.3.1
S_CONV, STRG_VAL, and VAL_STRG (Convert to/from character string and number)
instructions
You can convert number character strings to number values or number values to number
character strings with these instructions:
● S_CONV converts (number string to a number value) or (number value to a number
string)
● STRG_VAL converts a number string to a number value with format options
● VAL_STRG converts a number value to a number string with format options
S_CONV (convert character string)
Table 9- 18
String conversion instruction
LAD / FBD
SCL
out :=
_TO_(in);
Description
Converts a character string to the corresponding value, or a value
to the corresponding character string. The S_CONV instruction
has no output formatting options. This makes the S_CONV instruction simpler, but less flexible than the STRG_VAL and
VAL_STRG instructions.
1
For LAD / FBD: Click the "???" and select the data type from the drop-down list.
2
For SCL: Select S_CONV from the Extended Instructions, and answer the prompts for the data types for the conversion.
STEP 7 then provides the appropriate conversion instruction.
Table 9- 19
Data types (string to value)
Parameter and type
Data type
Description
IN
IN
String, WString
Input character string
OUT
OUT
String, WString, Char, WChar, SInt, Int, DInt, USInt, UInt, UDInt,
Real, LReal
Output number value
Conversion of the string parameter IN starts at the first character and continues until the end
of the string, or until the first character is encountered that is not "0" through "9", "+", "-", or
".". The result value is provided at the location specified in parameter OUT. If the output
number value does not fit in the range of the OUT data type, then parameter OUT is set to 0
and ENO is set to FALSE. Otherwise, parameter OUT contains a valid result and ENO is set
to TRUE.
Input String format rules:
● If a decimal point is used in the IN string, you must use the "." character.
● Comma characters "," used as a thousands separator to the left of the decimal point are
allowed and ignored.
● Leading spaces are ignored.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
347
Extended instructions
9.2 String and character
S_CONV (value to string conversion)
Table 9- 20
Data types (value to string)
Parameter and type
Data type
Description
IN
IN
String, WString, Char, WChar, SInt, Int, DInt, USInt, UInt, UDInt,
Real, LReal
Input number value
OUT
OUT
String, WString
Output character string
An integer, unsigned integer, or floating point value IN is converted to the corresponding
character string at OUT. The parameter OUT must reference a valid string before the
conversion is executed. A valid string consists of a maximum string length in the first byte,
the current string length in the second byte, and the current string characters in the next
bytes. The converted string replaces characters in the OUT string starting at the first
character and adjusts the current length byte of the OUT string. The maximum length byte of
the OUT string is not changed.
How many characters are replaced depends on the parameter IN data type and number
value. The number of characters replaced must fit within the parameter OUT string length.
The maximum string length (first byte) of the OUT string should be greater than or equal to
the maximum expected number of converted characters. The following table shows S_CONV
value to string conversion examples:
Output String format rules:
● Values written to parameter OUT do not use a leading "+" sign.
● Fixed-point representation is used (no exponential notation).
● The period character "." is used to represent the decimal point when parameter IN is the
Real data type.
● Values are right-justified in the output string and are preceded by space characters that
fill empty character positions.
S7-1200 Programmable controller
348
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Table 9- 21
IN data type
Maximum string lengths for each data type
Character
positions
allocated by
S_CONV
Converted string example1
Total string length including maximum and current length
bytes
USInt
4
"x255" 6
SInt
4
"-128" 6
UInt
6
"x65535" 8
Int
6
"-32768" 8
UDInt
11
"x4294967295" 13
DInt
11
"-2147483648" 13
Real
14
"x-3.402823E+38" 16
"x-1.175495E-38"
"x+1.175495E-38"
"x+3.402823E+38"
LReal
21
"-1.7976931348623E+308" 23
"-2.2250738585072E-308"
"+2.2250738585072E-308"
"+1.7976931348623E+308"
The "x" characters represent space characters that fill empty positions in the right-justified field that is allocated for the
converted value.
1
STRG_VAL (convert characer string to numerical value)
Table 9- 22
String-to-value instruction
LAD / FBD
SCL
"STRG_VAL"(
in:=_string_in,
format:=_word_in,
p:=uint_in,
out=>_variant_out);
Description
Converts a number character string to the corresponding
integer or floating point representation.
For LAD / FBD: Click the "???" and select the data type from the drop-down list.
1
Table 9- 23
Data types for the STRG_VAL instruction
Parameter and type
Data type
Description
IN
String, WString
The ASCII character string to convert
IN
FORMAT
IN
Word
Output format options
P
IN
UInt, Byte, USInt
IN: Index to the first character to be converted (first
character = 1)
OUT
OUT
SInt, Int, DInt, USInt, UInt, UDInt,
Real, LReal
Converted number value
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
349
Extended instructions
9.2 String and character
Conversion begins in the string IN at character offset P and continues until the end of the
string, or until the first character is encountered that is not "+", "-", ".", ",", "e", "E", or "0" to
"9". The result is placed at the location specified in parameter OUT.
String data must be initialized before execution as a valid string in memory.
The FORMAT parameter for the STRG_VAL instruction is defined below. The unused bit
positions must be set to zero.
Table 9- 24
Format of the STRG_VAL instruction
Bit
16
0
Bit 8 Bit 7
0
0
0
0
0
0
0
0
Bit 0
0
f = Notation format
1= Exponential notation
0 = Fixed point notation
r = Decimal point format
1 = "," (comma character)
0 = "." (period character)
Table 9- 25
0
0
0
0
f
r
Values of the FORMAT parameter
FORMAT (W#16#)
Notation format
Decimal point representation
0000 (default)
Fixed point
"."
0001
0002
","
Exponential
0003
0004 to FFFF
"."
","
Illegal values
Rules for STRG_VAL conversion:
● If the period character "." is used for the decimal point, then commas "," to the left of the
decimal point are interpreted as thousands separator characters. The comma characters
are allowed and ignored.
● If the comma character "," is used for the decimal point, then periods "." to the left of the
decimal point are interpreted as thousands separator characters. These period
characters are allowed and ignored.
● Leading spaces are ignored.
S7-1200 Programmable controller
350
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
VAL_STRG (convert numerical value to string)
Table 9- 26
Value-to-string operation
LAD / FBD
SCL
"VAL_STRG"(
in:=_variant_in,
size:=_usint_in,
prec:=_usint_in,
format:=_word_in,
p:=uint_in,
out=>_string_out);
Description
Converts an integer, unsigned integer, or floating point
value to the corresponding character string representation.
For LAD / FBD: Click the "???" and select the data type from the drop-down list.
1
Table 9- 27
Data types for the VAL_STRG instruction
Parameter and type
Data type
Description
IN
IN
SInt, Int, DInt, USInt, UInt, Value to convert
UDInt, Real, LReal
SIZE
IN
USInt
Number of characters to be written to the OUT string
PREC
IN
USInt
The precision or size of the fractional portion. This does
not include the decimal point.
FORMAT
IN
Word
Output format options
P
IN
UInt, Byte, USInt
IN: Index to the first OUT string character to be replaced
(first character = 1)
OUT
OUT
String, WString
The converted string
This instruction converts the value represented by parameter IN to a string referenced by
parameter OUT. The parameter OUT must be a valid string before the conversion is
executed.
The converted string replaces characters in the OUT string starting at character offset count
P to the number of characters specified by parameter SIZE. The number of characters in
SIZE must fit within the OUT string length, counting from character position P. If the SIZE
parameter is zero, then the characters overwrite at position P in the OUT string without
limitation. This instruction is useful for embedding number characters into a text string. For
example, you can put the numbers "120" into the string "Pump pressure = 120 psi".
Parameter PREC specifies the precision or number of digits for the fractional part of the
string. If the parameter IN value is an integer, then PREC specifies the location of the
decimal point. For example, if the data value is 123 and PREC = 1, then the result is "12.3".
The maximum supported precision for the Real data type is 7 digits.
If parameter P is greater than the current size of the OUT string, then spaces are added, up
to position P, and the result is appended to the end of the string. The conversion ends if the
maximum OUT string length is reached.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
351
Extended instructions
9.2 String and character
The FORMAT parameter for the VAL_STRG instruction is defined below. The unused bit
positions must be set to zero.
Table 9- 28
Format of the VAL_STRG instruction
Bit
16
0
Table 9- 29
Bit 8 Bit 7
0
0
0
0
0
0
0
0
Bit 0
0
0
0
s = Number sign character
1= use sign character "+" and "-"
0 = use sign character "-" only
f = Notation format
1= Exponential notation
0 = Fixed point notation
r = Decimal point format
1 = "," (comma character)
0 = "." (period character)
0
s
f
r
Values of the FORMAT parameter
FORMAT (WORD)
Number sign character
Notation format
Decimal point representation
W#16#0000
"-" only
Fixed point
"."
W#16#0001
","
W#16#0002
Exponential
W#16#0003
"."
","
W#16#0004
"+" and "-"
Fixed Point
W#16#0005
"."
","
W#16#0006
Exponential
W#16#0007
"."
","
W#16#0008 to W#16#FFFF
Illegal values
Parameter OUT string format rules:
● Leading space characters are added to the leftmost part of the string when the converted
string is smaller than the specified size.
● When the FORMAT parameter sign bit is FALSE, unsigned and signed integer data type
values are written to the output buffer without the leading "+" sign. The "-" sign is used if
required.
'.'
● When the sign bit is TRUE, unsigned and signed integer data type values are written to
the output buffer always with a leading sign character.
'.'
● When the FORMAT is set to exponential notation, Real data type values are written to the
output buffer as:
'.' 'E'
S7-1200 Programmable controller
352
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
● When the FORMAT is set to fixed point notation, integer, unsigned integer, and real data
type values are written to the output buffer as:
'.'
● Leading zeros to the left of the decimal point (except the digit adjacent to the decimal
point) are suppressed.
● Values to the right of the decimal point are rounded to fit in the number of digits to the
right of the decimal point specified by the PREC parameter.
● The size of the output string must be a minimum of three bytes more than the number of
digits to the right of the decimal point.
● Values are right-justified in the output string.
Conditions reported by ENO
When the conversion operation encounters an error, the instruction returns the following
results:
● ENO is set to 0.
● OUT is set to 0, or as shown in the examples for string to value conversion.
● OUT is unchanged, or as shown in the examples when OUT is a string.
Table 9- 30
ENO status
ENO
Description
1
No error
0
Illegal or invalid parameter; for example, an access to a DB that does not exist
0
Illegal string where the maximum length of the string is 0 or 255
0
Illegal string where the current length is greater than the maximum length
0
The converted number value is too large for the specified OUT data type.
0
The OUT parameter maximum string size must be large enough to accept the number of characters
specified by parameter SIZE, starting at the character position parameter P.
0
Illegal P value where P=0 or P is greater than the current string length
0
Parameter SIZE must be greater than parameter PREC.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
353
Extended instructions
9.2 String and character
Table 9- 31
IN string
OUT data type
OUT value
ENO
"123"
Int or DInt
123
TRUE
"-00456"
Int or DInt
-456
TRUE
"123.45"
Int or DInt
123
TRUE
"+2345"
Int or DInt
2345
TRUE
"00123AB"
Int or DInt
123
TRUE
"123"
Real
123.0
TRUE
"123.45"
Real
123.45
TRUE
"1.23e-4"
Real
1.23
TRUE
"1.23E-4"
Real
1.23
TRUE
"12,345.67"
Real
12345.67
TRUE
"3.4e39"
Real
3.4
TRUE
"-3.4e39"
Real
-3.4
TRUE
"1.17549e-38"
Real
1.17549
TRUE
"12345"
SInt
0
FALSE
"A123"
N/A
0
FALSE
""
N/A
0
FALSE
"++123"
N/A
0
FALSE
"+-123"
N/A
0
FALSE
Table 9- 32
1
Example of S_CONV string to value conversion
Examples of S_CONV value to string conversion
Data type
IN value
OUT string 1
ENO
UInt
123
"xxx123" TRUE
UInt
0
"xxxxx0" TRUE
UDInt
12345678
"xxx12345678" TRUE
Real
+9123.456
LReal
+9123.4567890123
"xx+9.123456E+3" TRUE
Real
-INF
"xxxxxxxxxxxINF" FALSE
Real
+INF
"xxxxxxxxxxxINF" FALSE
Real
NaN
"xxxxxxxxxxxNaN" FALSE
"xx+9.1234567890123 TRUE
E+3"
The "x" characters represent space characters that fill empty positions in the right-justified field
that is allocated for the converted value.
S7-1200 Programmable controller
354
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Table 9- 33
Example: STRG_VAL conversion
IN string
FORMAT
(W#16#....)
OUT data type
OUT value
ENO
"123"
0000
Int or DInt
123
TRUE
"-00456"
0000
Int or DInt
-456
TRUE
"123.45"
0000
Int or DInt
123
TRUE
"+2345"
0000
Int or DInt
2345
TRUE
"00123AB"
0000
Int or DInt
123
TRUE
"123"
0000
Real
123.0
TRUE
"-00456"
0001
Real
-456.0
TRUE
"+00456"
0001
Real
456.0
TRUE
"123.45"
0000
Real
123.45
TRUE
"123.45"
0001
Real
12345.0
TRUE
"123.45"
0000
Real
12345.0
TRUE
"123.45"
0001
Real
123.45
TRUE
".00123AB"
0001
Real
123.0
TRUE
"1.23e-4"
0000
Real
1.23
TRUE
"1.23E-4"
0000
Real
1.23
TRUE
"1.23E-4"
0002
Real
1.23E-4
TRUE
"12,345.67"
0000
Real
12345.67
TRUE
"12,345.67"
0001
Real
12.345
TRUE
"3.4e39"
0002
Real
+INF
TRUE
"-3.4e39"
0002
Real
-INF
TRUE
"1.1754943e-38"
(and smaller)
0002
Real
0.0
TRUE
"12345"
N/A
SInt
0
FALSE
"A123"
N/A
N/A
0
FALSE
""
N/A
N/A
0
FALSE
"++123"
N/A
N/A
0
FALSE
"+-123"
N/A
N/A
0
FALSE
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
355
Extended instructions
9.2 String and character
The following examples of VAL_STRG conversions are based on an OUT string initialized as
follows:
"Current Temp = xxxxxxxxxx C"
where the "x" character represents space characters allocated for the converted value.
Table 9- 34
Example: VAL_STRG conversion
Data type
IN value
P
SIZE
FORMAT
(W#16#....)
PREC
UInt
123
16
10
0000
0
UInt
UDInt
UDInt
Int
Int
Real
Real
Real
Real
Real
UDInt
0
12345678
12345678
123
-123
-0.00123
-0.00123
-INF
+INF
NaN
12345678
16
16
16
16
16
16
16
16
16
16
16
10
10
10
10
10
10
10
10
10
10
6
0000
0000
0001
0004
0004
0004
0006
N/A
N/A
N/A
N/A
2
3
3
0
0
4
4
4
4
4
3
OUT string
Current Temp
xxxxxxx123 C
Current Temp
xxxxxx0.00 C
Current Temp
x12345.678 C
Current Temp
x12345,678 C
Current Temp
xxxxxx+123 C
Current Temp
xxxxxx-123 C
Current Temp
0.0012 C
Current Temp
1.2300E-3 C
Current Temp
xxxxxx-INF C
Current Temp
xxxxxx+INF C
Current Temp
xxxxxxxNaN C
Current Temp
xxxxxxxxxx C
ENO
=
TRUE
=
TRUE
=
TRUE
=
TRUE
=
TRUE
=
TRUE
= xxx-
TRUE
= -
TRUE
=
FALSE
=
FALSE
=
FALSE
=
FALSE
S7-1200 Programmable controller
356
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.3.2
Strg_TO_Chars and Chars_TO_Strg (Convert to/from character string and array of
CHAR) instructions
Strg_TO_Chars copies an ASCII character string into an array of character bytes.
Chars_TO_Strg copies an array of ASCII character bytes into a character string.
Note
Only the zero based array types (Array [0..n] of Char) or (Array [0..n] of Byte) are allowed as
the input parameter Chars for the Chars_TO_Strg instruction, or as the IN_OUT parameter
Chars for the Strg_TO_Chars instruction.
Table 9- 35
Strg_TO_Chars instruction
LAD / FBD
SCL
Strg_TO_Chars(
Strg:=_string_in_,
pChars:=_dint_in_,
Cnt=>_uint_out_,
Chars:=_variant_inout_);
Table 9- 36
Description
The complete input string Strg is copied to an array of
characters at IN_OUT parameter Chars.
The operation overwrites bytes starting at array element
number specified by the pChars parameter.
Strings of all supported max lengths (1..254) may be used.
An end delimiter is not written; this is your responsibility.
To set an end delimiter just after the last written array
character, use the next array element number
[pChars+Cnt].
Data types for the parameters (Strg_TO_Chars)
Parameter and type
Data type
Description
Strg
IN
String, WString
Source string
pChars
IN
DInt
Array element number for the first string character written to
the target array
Chars
IN_OUT
Variant
The Chars parameter is a pointer to a zero-based array
[0..n] of characters copied from the input string. The array
can be declared in a DB or as local variables in the block
interface.
Example: "DB1".MyArray points to MyArray [0..10] of Char
element values in DB1.
Cnt
OUT
UInt
Count of characters copied
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
357
Extended instructions
9.2 String and character
Table 9- 37
Chars_TO_Strg instruction
LAD / FBD
SCL
Chars_TO_Strg(
Chars:=_variant_in_,
pChars:=_dint_in_,
Cnt:=_uint_in_,
Strg=>_string_out_);
Description
All or part of an array of characters is copied to a string.
The output string must be declared before Chars_TO_Strg is
executed. The string is then overwritten by the
Chars_TO_Strg operation.
Strings of all supported maximum lengths (1..254) may be
used.
The string maximum length value is not changed by
Chars_TO_Strg operation. Copying from array to string stops
when the maximum string length is reached.
A nul character '$00' or 16#00 value in the character array
works as a delimiter and ends copying of characters into the
string.
Table 9- 38
Data types for the parameters (Chars_TO_Strg)
Parameter and type
Data type
Description
Chars
IN
Variant
The Chars parameter is a pointer to zero based array [0..n] of
characters to be converted into a string. The array can be declared in a DB or as local variables in the block interface.
Example: "DB1".MyArray points to MyArray [0..10] of Char
element values in DB1.
pChars
IN
Dint
Element number for the first character in the array to copy.
Array element [0] is the default value.
Cnt
IN
UInt
Count of characters to copy: 0 means all
Strg
OUT
String, WString
Target string
Table 9- 39
ENO
ENO status
Description
1
No error
0
Chars_TO_Strg: Attempt to copy more character bytes to the output string than allowed by the maximum
length byte in the string declaration
0
Chars_TO_Strg: The nul character (16#00) value was found in the input character byte array.
0
Strg_TO_Chars: Attempt to copy more character bytes to the output array than are allowed by the element
number limit
S7-1200 Programmable controller
358
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.3.3
ATH and HTA (Convert to/from ASCII string and hexadecimal number) instructions
Use the ATH (ASCII to hexadecimal) and HTA (hexadecimal to ASCII) instructions for
conversions between ASCII character bytes (characters 0 to 9 and uppercase A to F only)
and the corresponding 4-bit hexadecimal nibbles.
Table 9- 40
ATH instruction
LAD / FBD
SCL
ret_val := ATH(
in:=_variant_in_,
n:=_int_in_,
Description
Converts ASCII characters into packed hexadecimal digits.
out=>_variant_out_);
Table 9- 41
Data types for the ATH instruction
Parameter type
Data Type
Description
IN
IN
Variant
Pointer to ASCII character byte array
N
IN
UInt
Number of ASCII character bytes to convert
RET_VAL
OUT
Word
Execution condition code
OUT
OUT
Variant
Pointer to the converted hexadecimal byte array
Conversion begins at the location specified by parameter IN and continues for N bytes. The
result is placed at the location specified by OUT. Only valid ASCII characters 0 to 9, lower
case a to f, and uppercase A to F can be converted. Any other character will be converted to
zero.
8-bit ASCII coded characters are converted to 4-bit hexadecimal nibbles. Two ASCII
characters can converted into a single byte containing two 4-bit hexadecimal nibbles.
The IN and OUT parameters specify byte arrays and not hexadecimal String data. ASCII
characters are converted and placed in the hexadecimal output in the same order as they
are read. If there are an odd number of ASCII characters, then zeros are put in the rightmost nibble of the last converted hexadecimal digit.
Table 9- 42
Examples: ASCII-to-hexadecimal (ATH) conversion
IN character bytes
N
OUT value
ENO
'0a23'
4
W#16#0A23
TRUE
'123AFx1a23'
10
16#123AF01023
FALSE
'a23'
3
W#16#A230
TRUE
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
359
Extended instructions
9.2 String and character
Table 9- 43
LAD / FBD
Table 9- 44
HTA instruction
SCL
ret_val := HTA(
in:=_variant_in_,
n:=_uint_in_,
out=>_variant_out_);
Description
Converts packed hexadecimal digits to their corresponding ASCII
character bytes.
Data types for the HTA instruction
Parameter and type
Data Type
Description
IN
IN
Variant
Pointer to input byte array
N
IN
UInt
Number of bytes to convert (each input byte has two 4-bit nibbles and
produces 2N ASCII characters)
RET_VAL
OUT
Word
Execution condition code
OUT
OUT
Variant
Pointer to ASCII character byte array
Conversion begins at the location specified by parameter IN and continues for N bytes. Each
4-bit nibble converts to a single 8-bit ASCII character and produces 2N ASCII character
bytes of output. All 2N bytes of the output are written as ASCII characters 0 to 9 through
uppercase A to F. The parameter OUT specifies a byte array and not a string.
Each nibble of the hexadecimal byte is converted into a character in the same order as they
are read in (left-most nibble of a hexadecimal digit is converted first, followed by the rightmost nibble of that same byte).
Table 9- 45
Examples: Hexadecimal -to- ASCII (HTA) conversion
IN value
N
OUT character bytes
ENO (ENO always TRUE after HTA execution)
W#16#0123
2
'0123'
TRUE
DW#16#123AF012
4
'123AF012'
TRUE
S7-1200 Programmable controller
360
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Table 9- 46
ATH and HTA condition codes
RET_VAL
(W#16#....)
Description
ENO
0000
No error
TRUE
0007
Invalid ATH input character: A character was found that was not an ASCII character 0- FALSE
9, lowercase a to f, or uppercase A to F
8101
Illegal or invalid input pointer, for example, an access to a DB that does not exist.
8120
Input string is an invalid format, i.e., max= 0, max=255, current>max, or grant length in FALSE
pointer < max
8182
Input buffer is too small for N
FALSE
8151
Data type not allowed for input buffer
FALSE
8301
Illegal or invalid output pointer, for example, an access to a DB that does not exist.
FALSE
8320
Output string is an invalid format, i.e., max= 0, max=255, current>max, or grant length
in pointer < max
FALSE
8382
Output buffer is too small for N
FALSE
8351
Data type not allowed for output buffer
FALSE
9.2.4
FALSE
String operation instructions
Your control program can use the following string and character instructions to create
messages for operator display and process logs.
9.2.4.1
MAX_LEN (Maximum length of a character string)
Table 9- 47
Maximum length instruction
LAD / FBD
SCL
out :=
MAX_LEN(in);
Description
MAX_LEN (Maximum length of string) provides the maximum length value
assigned to string IN at output OUT. If errors occur during processing of the
instruction, then an empty string length will be output.
The String and WString data types contain two lengths: the first byte (or word)
gives the maximum length and the second byte (or word) gives the current
length (this is the current number of valid characters).
•
The maximum length of the character string is assigned for each String or
WString declaration in square brackets. The number of bytes occupied by a
String is 2 bytes greater than the maximum length. The number of words
occupied by a WString is 2 words greater than the maximum length.
The current length represents the number of the characters actually used.
The current length must be less than or equal to the maximum length. The
current length is in bytes for a String and in words for a WString.
Use the MAX_LEN instruction to get the maximum length of the character
string and the LEN instruction to get the current length of a string.
•
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
361
Extended instructions
9.2 String and character
Table 9- 48
Data types for the parameters
Parameter and type
Data type
Description
IN
IN
String, WString
Input string
OUT
OUT
DInt
Maximum number of characters allowed for IN
string
9.2.4.2
Table 9- 49
LEN (Determine the length of a character string)
Length instruction
LAD / FBD
Table 9- 50
SCL
out := LEN(in);
Description
LEN (length) provides the current length of the string IN at output OUT. An
empty string has a length of zero.
Data types for the parameters
Parameter and type
Data type
Description
IN
IN
String, WString
Input string
OUT
OUT
Int, DInt, Real, LReal
Number of valid characters of IN string
Table 9- 51
ENO status
ENO
Condition
OUT
1
No invalid string condition
Valid string length
0
Current length of IN exceeds maximum length of IN
Current length is set to 0
Maximum length of IN does not fit within allocated memory range
Maximum length of IN is 255 (illegal length)
S7-1200 Programmable controller
362
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.4.3
Table 9- 52
CONCAT (Combine character strings)
Concatenate strings instruction
LAD / FBD
Table 9- 53
SCL
out := CONCAT(in1, in2);
Description
CONCAT (concatenate strings) joins string parameters IN1 and
IN2 to form one string provided at OUT. After concatenation,
String IN1 is the left part and String IN2 is the right part of the
combined string.
Data types for the parameters
Parameter and type
Data type
Description
IN1
IN
String, WString
Input string 1
IN2
IN
String, WString
Input string 2
OUT
OUT
String, WString
Combined string (string 1 + string 2)
Table 9- 54
ENO status
ENO
Condition
OUT
1
No errors detected
Valid characters
0
Resulting string after concatenation is larger than maximum length of OUT
string
Resulting string characters are
copied until the maximum length
of the OUT is reached
Current length of IN1 exceeds maximum length of IN1, current length of
IN2 exceeds maximum length of IN2, or current length of OUT exceeds
maximum length of OUT (invalid string)
Current length is set to 0
Maximum length of IN1, IN2 or OUT does not fit within allocated memory
range
Maximum length of IN1 or IN2 is 255, or the maximum length of OUT is 0
or 255 (String data type)
Maximum length of IN1 or IN2 is 65534, or the maximum length of OUT is
0 or 65534 (WString data type)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
363
Extended instructions
9.2 String and character
9.2.4.4
Table 9- 55
LEFT, RIGHT, and MID (Read substrings in a character string) instructions
Left, right and middle substring operations
LAD / FBD
SCL
out := LEFT(in, L);
out := MID(in, L, p);
Description
LEFT (Left substring) provides a substring made of the first L characters of string parameter IN.
•
If L is greater than the current length of the IN string, then the entire
IN string is returned in OUT.
•
If an empty string is the input, then an empty string is returned in
OUT.
MID (Middle substring) provides the middle part of a string. The middle
substring is L characters long and starts at character position P (inclusive)
If the sum of L and P exceeds the current length of the string parameter IN, then a substring is returned that starts at character position P
and continues to the end of the IN string.
out := RIGHT(in, L);
Table 9- 56
RIGHT (Right substring) provides the last L characters of a string.
•
If L is greater than the current length of the IN string, then the entire
IN string is returned in parameter OUT.
•
If an empty string is the input, then an empty string is returned in
OUT.
Data types for the parameters
Parameter and type
Data type
Description
IN
IN
String, WString
Input string
L
IN
Int
Length of the substring to be created:
P
IN
Int
•
LEFT uses the left-most characters number of characters in the
string
•
RIGHT uses the right-most number of characters in the string
•
MID uses the number of characters starting at position P within
the string
MID only: Position of first substring character to be copied
P= 1, for the initial character position of the IN string
OUT
OUT
String, WString
Output string
S7-1200 Programmable controller
364
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Table 9- 57
ENO status
ENO
Condition
1
No errors detected
0
OUT
Valid characters
Current length is set to 0
•
L or P is less than or equal to 0
•
P is greater than maximum length of IN
•
Current length of IN exceeds maximum length of IN, or current length
of OUT exceeds maximum length of OUT
•
Maximum length of IN or OUT does not fit within allocated memory
•
Maximum length of IN or OUT is 0 or 255 (String data type) or 0 or
65534 (WString data type)
Substring length (L) to be copied is larger than maximum length of OUT
string.
Characters are copied until the
maximum length of OUT is
reached
MID only: L or P is less than or equal to 0
Current length is set to 0
MID only: P is greater than maximum length of IN
Current length of IN1 exceeds maximum length of IN1, or current length of
IN2 exceeds maximum length of IN2 (invalid string)
Current length is set to 0
Maximum length of IN1, IN2 or OUT does not fit within allocated memory
range
Maximum length of IN1, IN2 or OUT is illegal length: 0 or 255 (String data
type) or 0 or 65534 (WString data type)
9.2.4.5
Table 9- 58
DELETE (Delete characters in a character string)
Delete substring instruction
LAD / FBD
Table 9- 59
SCL
out := DELETE(in, L, p);
Description
Deletes L characters from string IN. Character deletion starts at
character position P (inclusive), and the remaining substring is
provided at parameter OUT.
•
If L is equal to zero, then the input string is returned in OUT.
•
If the sum of L and P is greater than the length of the input
string, then the string is deleted to the end.
Data types for the parameters
Parameter and type
Data type
Description
IN
IN
String, WString
Input string
L
IN
Int
Number of characters to be deleted
P
IN
Int
Position of the first character to be deleted: The first character of
the IN string is position number 1
OUT
OUT
String, WString
Output string
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
365
Extended instructions
9.2 String and character
Table 9- 60
ENO
ENO status
Condition
OUT
1
No errors detected
Valid characters
0
P is greater than current length of IN
IN is copied to OUT with no characters deleted
Resulting string after characters are deleted is larger than maximum length Resulting string characters are
of OUT string
copied until the maximum length
of OUT is reached
L is less than 0, or P is less than or equal to 0
Current length is set to 0
Current length of IN exceeds maximum length of IN, or current length of
OUT exceeds maximum length of OUT
Maximum length of IN or OUT does not fit within allocated memory
Maximum length of IN or OUT is 0 or 255
9.2.4.6
Table 9- 61
LAD / FBD
Table 9- 62
INSERT (Insert characters in a character string)
Insert substring instruction
SCL
out := INSERT(in1, in2, p);
Description
Inserts string IN2 into string IN1. Insertion begins after the character at position P.
Data types for the parameters
Parameter and type
Data type
Description
IN1
IN
String, WString
Input string 1
IN2
IN
String, WString
Input string 2
P
IN
Int
Last character position in string IN1 before the insertion point for
string IN2
The first character of string IN1 is position number 1.
OUT
OUT
String, WString
Result string
S7-1200 Programmable controller
366
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Table 9- 63
ENO status
ENO
Condition
OUT
1
No errors detected
Valid characters
0
P is greater than length of IN1
IN2 is concatenated with IN1 immediately following the last IN1 character
P is less than 0
Current length is set to 0
Resulting string after insertion is larger than maximum length of
OUT string
Resulting string characters are copied
until the maximum length of OUT is
reached
Current length of IN1 exceeds maximum length of IN1, current
length of IN2 exceeds maximum length of IN2, or current length of
OUT exceeds maximum length of OUT (invalid string)
Current length is set to 0
Maximum length of IN1, IN2 or OUT does not fit within allocated
memory range
Maximum length of IN1 or IN2 is 255, or maximum length of OUT is
0 or 255 (String data type)
Maximum length of IN1 or IN2 is 65534, or maximum length of OUT
is 0 or 65534 (WString data type)
9.2.4.7
Table 9- 64
LAD / FBD
REPLACE (Replace characters in a character string)
Replace substring instruction
SCL
out := REPLACE(
in1:=_string_in_,
in2:=_string_in_,
L:=_int_in_,
p:=_int_in);
Description
Replaces L characters in the string parameter IN1. Replacement
starts at string IN1 character position P (inclusive), with replacement characters coming from the string parameter IN2.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
367
Extended instructions
9.2 String and character
Table 9- 65
Data types for the parameters
Parameter and type
Data type
Description
IN1
IN
String, WString
Input string
IN2
IN
String, WString
String of replacement characters
L
IN
Int
Number of characters to replace
P
IN
Int
Position of first character to be replaced
OUT
OUT
String, WString
Result string
If parameter L is equal to zero, then the string IN2 is inserted at position P of string IN1
without deleting any characters from string IN1.
If P is equal to one, then the first L characters of string IN1 are replaced with string IN2
characters.
Table 9- 66
ENO
ENO status
Condition
OUT
1
No errors detected
Valid characters
0
P is greater than length of IN1
IN2 is concatenated with IN1 immediately following the last IN1 character
P points within IN1, but fewer than L characters remain in IN1
IN2 replaces the end characters of IN1
beginning at position P
Resulting string after replacement is larger than maximum length of
OUT string
Resulting string characters are copied
until the maximum length of OUT is
reached
Maximum length of IN1 is 0
IN2 characters are copied to OUT
L is less than 0, or P is less than or equal to 0
Current length is set to 0
Current length of IN1 exceeds maximum length of IN1, current
length of IN2 exceeds maximum length of IN2, or current length of
OUT exceeds maximum length of OUT
Maximum length of IN1, IN2 or OUT does not fit within allocated
memory range
Maximum length of IN1 or IN2 is 255, or maximum length of OUT is
0 or 255 (String data type)
Maximum length of IN1 or IN2 is 65534, or maximum length of OUT
is 0 or 65534 (WString data type)
S7-1200 Programmable controller
368
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.4.8
Table 9- 67
FIND (Find characters in a character string)
Find substring instruction
LAD / FBD
Table 9- 68
SCL
out := FIND(
in1:=_string_in_,
in2:=_string_in);
Description
Provides the character position of the substring specified by IN2 within
the string IN1. The search starts on the left. The character position of
the first occurrence of IN2 string is returned at OUT. If the string IN2 is
not found in the string IN1, then zero is returned.
Data types for the parameters
Parameter and type
Data type
Description
IN1
IN
String, WString
Search inside this string
IN2
IN
String, WString
Search for this string
OUT
OUT
Int
Character position in string IN1 of the first search match
Table 9- 69
ENO status
ENO
Condition
OUT
1
No errors detected
Valid character position
0
IN2 is larger than IN1
Character position is set to 0
Current length of IN1 exceeds maximum length of IN1, or current length
of IN2 exceeds maximum length of IN2 (invalid string)
Maximum length of IN1 or IN2 does not fit within allocated memory
range
Maximum length of IN1 or IN2 is 255 (String data type) or 65535
(WString data type)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
369
Extended instructions
9.2 String and character
9.2.5
Runtime information
9.2.5.1
GetSymbolName (Read out a tag on the input parameter)
Table 9- 70
GetSymbolName instruction
LAD / FBD
SCL
OUT := GetSymbolName(
variable:=_parameter_in_,
size:=_dint_in_);
Description
The GetSymbolName instruction returns a
string corresponding to the name of a variable
from the block interface.
Your program can call the instruction multiple
times with different tags. The process value of
the tag is irrelevant.
The instruction returns the name read at the
OUT parameter.
Parameter
The following table shows the parameters of the GetSymbolName instruction:
Parameter
Declaration
Data type
VARIABLE
Input
PARAMETER Parameter
sections Input,
Output, InOut
Variable from the local block interface for which you
want a string value of the name returned
SIZE
Input
DINT
Limits the number of characters output at the OUT
parameter:
OUT
Return
WSTRING
Memory area
I, Q, M, D, L
I, Q, M, D, L
Description
•
SIZE > 0: GetSymbolName returns the first SIZE
characters of the name.
•
SIZE = 0: GetSymbolName returns the entire
name.
•
SIZE < 0: GetSymbolName returns the last SIZE
characters of the name.
Output of the tag name supplied by the input parameter
You specify the input parameters of the block interface at the VARIABLE parameter. Use
only an interface parameter for this parameter and not a PLC or data block tag.
To limit the length of the read tag name, use the SIZE parameter. If the instruction truncates
the name, it indicates the truncation by the characters "..." (Unicode character 16#2026)
appears at the end of the name. Note that this character has the length 1.
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
370
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Example: Meaning of SIZE parameter
The following example illustrates the meaning of the SIZE parameter. The following tag
name is read from the block interface: "MyPLCTag" (The double quotes at the start and end
belong to the name.)
SIZE
GetSymbolName returns
Explanation
1
'...'
•
First character of WSTRING:'
•
Identifier that the name was truncated: ...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first character of the name and identifier that the
name was truncated:"...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first two characters of the name and identifier that
the name was truncated:"... "M...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first five characters of the name and identifier that
the name was truncated: "MyPL...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
All characters of the name: "MyPLCTag"
•
Last character of WSTRING:'
2
3
6
0
'"...'
'"M...'
'"MyPL...'
'"MyPLCTag"'
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
371
Extended instructions
9.2 String and character
Example: Reading a symbol name
In the following example, you read out the name of a tag that is interconnected via the input
parameter of a block.
Create two tags in a global data block for storing the data.
Create an input parameter inputValue with the BYTE data type in the Level1 block. Call the
GetSymbolName instruction in the Level1 block. Interconnect the parameters of the
instruction as follows.
Interconnect the inputValue parameter of the Level1 block as follows.
The GetSymbolName instruction is executed in the Level1 block. Input parameter inputValue
of the Level1 block is examined for its interconnection using input parameter VARIABLE of
the instruction. In doing so, the symbolVALUE tag is read out and output as a character
string at output parameter OUT ("MySymNAME"). According to the value of input parameter
SIZE, the length of the character string is limited to 60 characters.
S7-1200 Programmable controller
372
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.5.2
Table 9- 71
GetSymbolPath (Query composite global name of the input parameter assignment)
GetSymbolPath instruction
LAD / FBD
SCL
OUT := GetSymbolPath(
variable:=_parameter_in_,
size:=_dint_in_);
Description
The GetSymbolPath instruction reads the
composite global name of an input parameter
at the local interface of a block (FB or FC). The
name consists of the storage path and the tag
name.
Your program can call the instruction multiple
times with different tags. The process value of
the tag is irrelevant.
The instruction returns the name read at the
OUT parameter.
Parameter
The following table shows the parameters of the GetSymbolPath instruction:
Parameter
Declaration
Data type
Memory area
Description
VARIABLE
Input
PARAMETER
Parameter sections
Input, Output, InOut
Selection of the local interface to which you
want to read the global name of the input
parameter supply.
SIZE
Input
DINT
I, Q, M, D, L or constant
Limits the number of characters output at the
OUT parameter.
OUT
Output
WSTRING
I, Q, M, D, L
•
SIZE > 0: GetSymbolPath returns the first
SIZE characters of the name.
•
SIZE = 0: GetSymbolPath returns the
entire name.
•
SIZE < 0: GetSymbolPath returns the last
SIZE characters of the name.
Output of the tag name of the input parameters supply.
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
373
Extended instructions
9.2 String and character
Usage
Note the following tips on using the GetSymbolPath instruction:
● Specify the block interface through which the name of the input tag is read at the
VARIABLE parameter of the instruction:
– If a data block tag supplies the input parameter, GetSymbolPath outputs the name of
the DB, contained structures and the name of the tag.
– If a PLC tag supplies the input parameters GetSymbolPath outputs the name of the
PLC tag.
– If a constant supplies the input parameter, GetSymbolPath outputs the constant value.
● To limit the length of the read tag name, use the SIZE parameter. If the name has been
truncated, this is indicated by the character "..." (Unicode character 16#2026) at the end
of the name. Note that this character has the length 1.
Example: Meaning of the SIZE parameter
The following example illustrates the meaning of the SIZE parameter. GetSymbolPath has
read out the following tag name is read out from the block interface: "MyPLCTag" (The
double quotes at the start and end belong to the name.)
SIZE
GetSymbolPath returns
Explanation
1
'...'
•
First character of WSTRING:'
•
Identifier that the name was truncated: ...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first character of the name and identifier that the
name was truncated:"...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first two characters of the name and identifier that
the name was truncated:"... "M...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first five characters of the name and identifier that
the name was truncated: "MyPL...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
All characters of the name: "MyPLCTag"
•
Last character of WSTRING:'
2
3
6
0
'"...'
'"M...'
'"MyPL...'
'"MyPLCTag"'
S7-1200 Programmable controller
374
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Example: Calling GetSymbolPath over mutiple block call levels
The following example shows the use of GetSymbolPath over several call levels:
● Organization block OB1 calls the FB_Level_1 block, which in turn calls the FB_Level_2
block.
● The FB_Level_2 block executes GetSymbolPath to read the path of the parameter at the
REQ2 interface.
● Since the REQ1 interface supplies REQ2, the instruction determines the path of the input
parameter of REQ1.
● The MyStarterBit tag is the REQ1 input parameter. The bit is located in the MySTRUCT
structure in the MyDatablock data block.
GetSymbolPath reads this information and outputs the path
("MyDataBlock".MySTRUCT.MyStarterBit) at the OUT parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
375
Extended instructions
9.2 String and character
9.2.5.3
Table 9- 72
GetInstanceName (Read out name of the block instance)
GetInstanceName instruction
LAD / FBD
SCL
OUT := GetInstanceName(
size:=_dint_in_);
Description
You can use the GetInstanceName instruction
to read the name of the instance data block
within a function block.
Parameter
The following table shows the parameters of the GetInstanceName instruction:
Parameter
Declaration
Data type
Memory area
Description
SIZE
Input
DINT
I, Q, M, D, L or
constant
Limits the number of characters output at the OUT
parameter.
OUT
Output
WSTRING
I, Q, M, D, L
•
SIZE > 0: GetInstanceName returns the first SIZE
characters of the name.
•
SIZE = 0: GetInstanceName returns the entire
name.
•
SIZE < 0: GetInstanceName returns the last SIZE
characters of the name.
Read name of the instance data block
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
376
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Example: Meaning of SIZE parameter
To limit the length of the read instance name, use the SIZE parameter. If the instruction has
truncated the name, it indicates the truncation by the character "..." (Unicode character
16#2026) at the end of the name. Note that this character has the length 1.
The following example illustrates the meaning of the SIZE parameter. GetInstanceName has
read out the following instance name from the block interface: "Level1_DB" (The double
quotes at the start and end belong to the name.)
SIZE
GetSymbolPath returns
Explanation
1
'...'
•
First character of WSTRING:'
•
Identifier that the name was truncated: ...
•
Last character of WSTRING:'
2
3
6
0
'"...'
'"L...'
'"Leve...'
'"Level1_DB"'
•
First character of WSTRING:'
•
The first character of the name and identifier that the
name was truncated:"...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first two characters of the name and identifier that
the name was truncated:"... "L...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first five characters of the name and identifier that
the name was truncated: "Leve...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
All characters of the name: "Level1_DB"
•
Last character of WSTRING:'
GetInstanceName writes out the name of the instance data block to the OUT parameter. The
instruction truncates the name if the name of the instance data block is longer than the
maximum length of WSTRING.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
377
Extended instructions
9.2 String and character
Example: Reading the name of an instance data block
The following example shows how to read out the name of an instance data block.
Create two tags in a global data block for storing the data.
Define the parameters of the instruction as follows.
The Level1_gin block executes the GetInstanceName instruction, which determines the
associated instance data block of the Level1_gin block and outputs the name as a character
string at output parameter OUT (outputInstName). According to the value 0 of parameter
SIZE (limitSIZE), the length of the character string is unlimited.
S7-1200 Programmable controller
378
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
9.2.5.4
Table 9- 73
GetInstancePath (Query composite global name of the block instance)
GetInstancePath instruction
LAD / FBD
SCL
OUT := GetInstancePath(
size:=_dint_in_);
Description
You use the GetInstancePath instruction to
read the composed global name of the block
instance within a function block. The composed global name of the block instance is the
path of the complete call hierarchy when the
program calls multiple instances.
Parameter
The following table shows the parameters of the GetInstancePath instruction:
Parameter
Declaration
Data type
Memory area
Description
SIZE
Input
DINT
I, Q, M, D, L or constant
Limits the number of characters output at the
OUT parameter.
OUT
Output
WSTRING
I, Q, M, D, L
•
SIZE > 0: GetInstancePath returns the first
SIZE characters of the name.
•
SIZE = 0: GeInstancePath returns the
entire name.
•
SIZE < 0: GetInstancePath returns the last
SIZE characters of the name.
Read global name of the block instance.
If the global name of the block instance is
longer than the maximum length of WSTRING
(254 characters), GetInstancePath truncates
the name.
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
379
Extended instructions
9.2 String and character
Example: Calling GetInstancePath to get the path of a multi-instance FB call
In the following example, the FB_Level_3 function block calls the GetInstancePath
instruction.
● The FB_Level_3 function block stores its data in the calling FB_Level_2 function block.
● The FB_Level_2 function block in turn stores its data in the calling FB_Level_1 function
block.
● The FB_Level_1 function block in turn stores its data in its instance data block
IDB_LEVEL_1. Through the use of multi-instances, the instance data block of FB_Level_1
contains all data of the three function blocks.
The GetInstancePath instruction returns the following values for this example, depending on
the value of the SIZE parameter:
SIZE
GetInstancePath returns
Explanation
1
'...'
•
First character of WSTRING:'
•
Identifier that the name was truncated: ...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first character of the name and identifier that the
name was truncated:"...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first two characters of the name and identifier that
the name was truncated:"... "I...
•
Last character of WSTRING:'
2
3
'"...'
'"I...'
S7-1200 Programmable controller
380
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
SIZE
GetInstancePath returns
Explanation
6
'"IDB_...'
•
First character of WSTRING:'
•
The first five characters of the name and identifier that
the name was truncated: "IDB_...
•
Last character of WSTRING:'
0
'"IDB_LEVEL_1".Level_2_
•
Instance.Level_3_Instance' •
•
First character of WSTRING:'
All characters of the name:
"IDB_LEVEL_1".Level_2_Instance.Level_3_Instance
Last character of WSTRING:'
Note
Use of GetInstancePath in function blocks with single instance
If the function block in which you call GetInstancePath saves data in its own instance data
block, GetInstancePath outputs the name of the single instance as the global name. The
result at parameter OUT corresponds in this case to the GetInstanceName (Page 376)
instruction.
9.2.5.5
Table 9- 74
GetBlockName (Read out name of the block)
GetBlockName instruction
LAD / FBD
SCL
RET_VAL := GetBlockName(
size:=_dint_in_);
Description
You use the GetBlockName instruction to read
the name of the block in which the instruction
is called.
Parameter
The following table shows the parameters of the GetBlockName instruction:
Parameter
Declaration
Data type
Memory area
Description
SIZE
Input
UINT
I, Q, M, D, L or
constant
Limits the number of characters output at the
RET_VAL parameter.
RET_VAL
Output
WSTRING
I, Q, M, D, L
•
SIZE > 0: GetBlockName returns the first SIZE
characters of the name.
•
SIZE = 0: GetBlockName returns the entire name.
•
SIZE < 0: GetBlockName returns the last SIZE
characters of the name.
Read name of the instance data block
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
381
Extended instructions
9.2 String and character
Example: Meaning of the SIZE parameter
To limit the length of the block name to a certain number of characters, specify the maximum
length at the SIZE parameter. If GetBlockName truncates the name, it indicates the
truncation by the character "..." (Unicode character 16#2026) at the end of the name. Note
that this character has the length 1.
The following example illustrates the meaning of the SIZE parameter. GetBlockName has
read out the following block name: Level1_gbn (The double quotes at the start and end
belong to the name.)
SIZE
GetBlockName returns
Explanation
1
'...'
•
First character of WSTRING:'
•
Identifier that the name was truncated: ...
•
Last character of WSTRING:'
2
3
6
0
'"...'
'"L...'
'"Leve...'
'"Level1_gbn"'
•
First character of WSTRING:'
•
The first character of the name and identifier that the
name was truncated:"...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first two characters of the name and identifier that
the name was truncated:"... "L...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
The first five characters of the name and identifier that
the name was truncated: "Leve...
•
Last character of WSTRING:'
•
First character of WSTRING:'
•
All characters of the name: "Level1_gbn"
•
Last character of WSTRING:'
GetBlockName writes the name of the block at the RET_VAL parameter. If the name of the
block is longer than the maximum length of WSTRING, it truncates the name.
S7-1200 Programmable controller
382
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.2 String and character
Example: Reading a block name
The following example shows how to read out a block name.
1. Create two tags in a global data block for storing the data.
2. Define the parameters of the instruction as follows:
The Level1_gbn block executes the GetBlockName instruction. GetBlockName reads out the
name of the Level1_gbn block and outputs the name as a character string at output
parameter RET_VAL(outputBlockName). Because the SIZE parameter is 0 (limitSIZE), the
length of the character string is unlimited.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
383
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3
Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.1
Distributed I/O Instructions
The following Distributed I/O instructions can be used with PROFINET, PROFIBUS, or AS-i:
● RDREC instruction (Page 385): Reads a data record with the number INDEX from a
module or device.
● WRREC instruction (Page 385): Transfers a data record with the number INDEX to a
module or device defined by ID.
● GETIO instruction (Page 388): Consistently reads out all inputs of a DP standard slave /
PROFINET IO device.
● SETIO instruction (Page 389): Consistently transfers data from the source range defined
by the OUTPUTS parameter to the addressed DP standard slave / PROFINET IO device.
● GETIO_PART instruction (Page 390): Consistently reads out a related part of the inputs
of an IO module.
● SETIO_PART instruction (Page 392): Consistently writes data from the source area
spanned by the OUTPUTS parameter to the outputs of an IO module.
● RALRM instruction (Page 394): Allows you to receive an interrupt with all corresponding
information from a module or device and supply this information to its output parameters.
● DPRD_DAT instruction (Page 408): Allows you to read consistent data areas greater than
64 bytes from a module or device with the DPRD_DAT instruction.
● DPWR_DAT instruction (Page 408): Allows you to write consistent data areas greater
than 64 bytes to a module or device with the DPWR_DAT instruction.
The D_ACT_DP instruction (Page 398) allows you to disable and enable configured
PROFINET IO devices in a targeted manner. You can also determine whether each
assigned PROFINET IO device is currently activated or deactivated.
Note
Note: You can only use the D_ACT_DP instruction with PROFINET IO devices. You cannot
use the instruction with PROFIBUS DP slaves.
The DPNRM_DG instruction (Page 416) allows you to read the current diagnostic data of a
DP slave in the format specified by EN 50 170 Volume 2, PROFIBUS.
Note
You can only use the DPNRM_DG instruction with PROFIBUS.
S7-1200 Programmable controller
384
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.2
RDREC and WRREC (Read/write data record)
You can use the RDREC (Read data record) and WRREC (Write data record) instructions
with PROFINET, PROFIBUS, and AS-i.
Table 9- 75
RDREC and WRREC instructions
LAD / FBD
SCL
"RDREC_DB"(
req:=_bool_in_,
ID:=_word_in_,
index:=_dint_in_,
mlen:=_uint_in_,
valid=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_dword_out_,
len=>_uint_out_,
record:=_variant_inout_);
"WRREC_DB"(
req:=_bool_in_,
ID:=_word_in_,
index:=_dint_in_,
len:=_uint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_dword_out_,
record:=_variant_inout_);
Description
Use the RDREC instruction to read a data
record with the number INDEX from the
component addressed by the ID, such as
a central rack or a distributed component
(PROFIBUS DP or PROFINET IO). Assign the maximum number of bytes to
read in MLEN. The selected length of the
target area RECORD should have at
least the length of MLEN bytes.
Use the WRREC instruction to transfer a
data RECORD with the record number
INDEX to a DP slave/PROFINET IO device component addressed by ID, such as
a module in the central rack or a distributed component (PROFIBUS DP or
PROFINET IO).
Assign the byte length of the data record
to be transmitted. The selected length of
the source area RECORD should, therefore, have at least the length of LEN
bytes.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL examples, "RDREC_DB" and "WRREC_DB" are the names of the instance DBs.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
385
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Table 9- 76
RDREC and WRREC data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
REQ = 1: Transfer data record
ID
IN
HW_IO (Word)
Logical address of the DP slave/PROFINET IO component
(module or submodule):
•
For an output module, bit 15 must be set (for example, for
address 5: ID:= DW#16#8005).
For a combination module, the smaller of the two addresses
should be specified.
Note: In V3.0, the device ID can be determined in one of two
ways:
•
•
•
By making the following "Network view" selections:
–
Device (gray box)
–
"Properties" of the device
–
"Hardware identifier"
Note: Not all devices display their Hardware identifiers,
however.
By making the following "Project tree" menu selections:
–
PLC tags
–
Default tag table
–
System constants tab
All configured device Hardware identifiers are displayed.
Note: In V4.0, the device ID (hardware identifier) for the interface
module is determined by going to the tag table and locating the
"Device Name [HEAD]" parameter under System Constants.
INDEX
IN
Byte, Word, USInt,
UInt, SInt, Int, DInt
Data record number
MLEN
IN
Byte, USInt, UInt
Maximum length in bytes of the data record information to be
fetched (RDREC)
VALID
OUT
Bool
New data record was received and valid (RDREC). The VALID
bit is TRUE for one scan, after the last request was completed
with no error.
DONE
OUT
Bool
Data record was transferred (WRREC). The DONE bit is TRUE
for one scan, after the last request was completed with no error.
BUSY
OUT
Bool
•
BUSY = 1: The read (RDREC) or write (WRREC) process is
not yet terminated.
•
BUSY = 0: Data record transmission is completed.
ERROR
OUT
Bool
ERROR = 1: A read (RDREC) or write (WRREC) error has occurred. The ERROR bit is TRUE for one scan, after the last
request was terminated with an error. The error code value at
the STATUS parameter is valid only during the single scan
where ERROR = TRUE.
STATUS
OUT
DWord
Block status (Page 403) or error information (Page 553)
S7-1200 Programmable controller
386
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameter and type
Data type
Description
LEN
OUT (RDREC)
IN (WRREC)
UInt
•
Length of the fetched data record information (RDREC)
•
Maximum byte length of the data record to be transferred
(WRREC)
IN_OUT
Variant
•
Target area for the fetched data record (RDREC)
•
Data record (WRREC)
RECORD
The RDREC and WRREC instructions operate asynchronously, that is, processing covers
multiple instruction calls. Start the job by calling RDREC or WRREC with REQ = 1.
The job status is displayed via output parameter BUSY and the two central bytes of output
parameter STATUS. The transfer of the data record is complete when the output parameter
BUSY has been set to FALSE
A value of TRUE (only for one scan) on the output parameter VALID (RDREC) or DONE
(WRREC) verifies that the data record has been successfully transferred into the target area
RECORD (RDREC) or to the target device (WRREC). In the case of the RDREC, the output
parameter LEN contains the length of the fetched data in bytes.
The output parameter ERROR (only for one scan when ERROR = TRUE) indicates that a
data record transmission error has occurred. In this case, the output parameter STATUS
(only for the one scan when ERROR = TRUE) contains the error information.
Data records are defined by the hardware device manufacturer. Refer to the hardware
manufacturer's device documentation for details about a data record.
You can have up to four RDREC instructions and four WRREC instructions in use at the
same time.
Note
If you configure a DPV1 slave with a GSD file (GSD rev. 3 and higher) and the DP interface
of the DP master is set to "S7 compatible", then you might not read any data records from
the I/O modules in the user program with "RDREC" or write to the I/O modules with
"WRREC". In this case, the DP master addresses the wrong slot (configured slot + 3).
Remedy: set the interface of the DP master to "DPV1".
Note
The interfaces of the "RDREC" and "WRREC" instructions are identical to the "RDREC" and
"WRREC" FBs defined in "PROFIBUS Guideline PROFIBUS Communication and Proxy
Function Blocks according to IEC 61131-3".
Note
If you use "RDREC" or "WRREC" to read or write a data record for PROFINET IO, then the
CPU interprets negative values in the INDEX, MLEN, and LEN parameters as unsigned 16bit integers.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
387
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.3
GETIO (Read process image)
You use the instruction "GETIO" to consistently read inputs of modules or submodules of
DP slaves and PROFINET IO devices. The instruction "GETIO" calls the instruction
"DPRD_DAT (Page 408)". If there is no error during the data transmission, the data that has
been read is entered in the destination area indicated by INPUTS.
Table 9- 77
GETIO (Read process image) instruction
LAD / FBD
SCL
"GETIO_DB"(
id:=_uint_in_,
status=>_dword_out_,
len=>_int_out_,
inputs:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "GETIO_DB" is the name of the instance DB.
Description
Use the instruction "GETIO" to consistently read out all inputs of a
DP standard slave /
PROFINET IO device.
The destination area must have a length that is greater than or equal to the length of the
selected component.
If you read from a DP standard slave with a modular configuration or with several DP
identifiers, you only access the data of one component / DP identifier at the configured start
address with a "GETIO" call.
Parameters
The following table shows the parameters of the "GETIO" instruction:
Parameter
Declaration
Data type
Description
ID
IN
HW_SUBMOD Hardware ID of the DP standard slave / PROFINET IO device
ULE
STATUS1
OUT
DWord
Contains the error information of "DPRD_DAT (Page 408)" in the form
DW#16#40xxxx00
LEN
OUT
Int
Amount of data read in bytes
INPUTS
IN_OUT
Variant
Destination area for the read data: The destination area must have a
length that is greater than or equal to the length of the selected
DP standard slave / PROFINET IO device.
You can use the following data types:
1
•
System data types and array of system data types: BYTE, CHAR,
SINT, USINT, WORD, INT, UINT, DWORD, DINT, UDINT, REAL,
LREAL, LWORD, LINT, ULINT
•
User Defined Types (UDT)
•
Structures (STRUCT), but only in non-optimized data blocks (DB)
When displaying the "GETIO" error codes, use the DWord data type.
S7-1200 Programmable controller
388
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.4
SETIO (Transfer process image)
You use the instruction "SETIO" to consistently transfer data from the source range defined
by the OUTPUTS parameter to the addressed modules or submodules of DP slaves and
PROFINET IO devices. If you have configured the relevant address area of the
DP standard slave / PROFINET IO device as a consistent range in a process image, the
data is transferred to the process image. "SETIO" calls the "DPWR_DAT (Page 408)"
instruction during this transfer.
Table 9- 78
SETIO (Read process image) instruction
LAD / FBD
SCL
"SETIO_DB"(
id:=_uint_in_,
status=>_dword_out_,
outputs:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "SETIO_DB" is the name of the instance DB.
Description
Use the instruction "SETIO" to consistently transfer data from the
source range defined by the parameter OUTPUTS to the addressed
DP standard slave /
PROFINET IO device.
The source range must have a length that is greater than or equal to the length of the
selected component.
In the case of a DP standard slave / PROFINET IO device with modular configuration or with
several DP identifiers, you can only access one DP identifier / component per "SETIO" call.
Parameters
The following table shows the parameters of the "SETIO" instruction:
Parameter
Declaration
Data type
Description
ID
IN
HW_SUBMOD Hardware ID of the DP standard slave / PROFINET IO device
ULE
STATUS1
OUT
DWord
Contains the error information of "DPWR_DAT (Page 408)" in the form
DW#16#40xxxx00
OUTPUTS
IN_OUT
Variant
Source range for the data to be written: The source range must have a
length that is greater than or equal to the length of the selected DP standard slave / PROFINET IO device.
You can use the following data types:
1
•
System data types and array of system data types: BYTE, CHAR,
SINT, USINT, WORD, INT, UINT, DWORD, DINT, UDINT, REAL,
LREAL, LWORD, LINT, ULINT
•
User Defined Types (UDT)
•
Structures (STRUCT), but only in non-optimized data blocks (DB)
When displaying the "SETIO"error codes, use the DWord data type.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
389
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.5
GETIO_PART (Read process image area)
You use the instruction "GETIO_PART" to consistently read a related part of the inputs of
modules or submodules of DP slaves and PROFINET IO devices. GETIO_PART calls the
instruction "DPRD_DAT (Page 408)".
Table 9- 79
LAD / FBD
GETIO_PART (Read process image area) instruction
SCL
"GETIO_PART_DB"(
id:=_uint_in_,
offset:=_int_in_,
len:=_int_in_,
status=>_dword_out_,
error=>_bool_out_,
inputs:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "GETIO_PART_DB" is the name of the instance DB.
Description
Use the instruction GETIO_PART to
consistently read out a related part of
the inputs of an IO module.
Use the ID input parameter to select the IO module by means of the hardware ID.
Use the OFFSET and LEN parameters to specify the portion of the process image area to be
read. If the input area spanned by OFFSET and LEN is not completely covered by the
module, the block returns the error code DW#16#4080B700.
The length of the destination area must be larger than or equal to the amount of bytes to be
read:
● If there is no error during the data transmission, ERROR receives the value FALSE. The
data that is read is written to the destination area defined at the INPUTS parameter.
● If there is an error during the data transmission, ERROR receives the value TRUE. The
STATUS parameter receives the error information from DPRD_DAT.
● If the destination area is greater than LEN, the instruction writes to the first LEN bytes of
the destination area. ERROR receives the value FALSE.
S7-1200 Programmable controller
390
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameters
The following table shows the parameters of the GETIO_PART instruction:
Parameter
Declaration
Data type
Description
ID
IN
HW_SUBMO
DULE
Hardware identifier of the module
OFFSET
IN
Int
Number of the first byte to be read in the process image for the component
(smallest possible value: 0)
LEN
IN
Int
Number of bytes to be read
STATUS1
OUT
DWord
Contains the error information of DPRD_DAT (Page 408) in the form
DW#16#40xxxx00, if ERROR = TRUE
ERROR
OUT
Bool
Error display: ERROR = TRUE if an error occurs when DPRD_DAT
(Page 408) is called
INPUTS
IN_OUT
Variant
Destination area for read data: If the destination area is greater than LEN,
the instruction writes to the first LEN bytes of the destination area.
You can use the following data types:
•
1
System data types and array of system data types: BYTE, CHAR,
SINT, USINT, WORD, INT, UINT, DWORD, DINT, UDINT, REAL,
LREAL, LWORD, LINT, ULINT
•
User Defined Types (UDT)
•
Structures (STRUCT), but only in non-optimized data blocks (DB)
When displaying the GETIO_PART error codes, use the DWord data type.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
391
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.6
SETIO_PART (Transfer process image area)
You can use the "SETIO_PART" instruction to consistently write data from the source area
spanned by OUTPUTS to the outputs of modules or submodules of DP slaves and
PROFINET IO devices. SETIO_PART calls the instruction "DPWR_DAT (Page 408)".
Table 9- 80
LAD / FBD
SETIO_PART (Transfer process image area) instruction
SCL
"SETIO_PART_DB"(
id:=_uint_in_,
offset:=_int_in_,
len:=_int_in_,
status=>_dword_out_,
error=>_bool_out_,
outputs:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "SETIO_PART_DB" is the name of the instance DB.
Description
Use the instruction SETIO_PART to
consistently write data from the
source area spanned by OUTPUTS
to the outputs of an IO module.
With the input parameter ID, you select the I/O module based on the hardware identified.
With the parameters OFFSET and LEN, you assign the portion of the process image area to
be written for the component addressed by ID. If the output area spanned by OFFSET and
LEN is not completely covered by the module, the block returns the error code
DW#16#4080B700.
The length of the destination area must be larger than or equal to the amount of bytes to be
read:
● If there is no error during the data transmission, ERROR receives the value FALSE.
● If there is an error during the data transmission, ERROR receives the value TRUE, and
STATUS receives the error information of DPWR_DAT.
● If the source area is greater than LEN, the instruction transfers the first LEN bytes from
OUTPUTS. ERROR receives the value FALSE.
S7-1200 Programmable controller
392
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameters
The following table shows the parameters of the SETIO_PART instruction:
Parameter
Declaration
Data type
Description
ID
IN
HW_SUBMO
DULE
Hardware identifier of the IO module
OFFSET
IN
Int
Number of the first byte to be written in the process image for the component (smallest possible value: 0)
LEN
IN
Int
Number of bytes to be written
STATUS1
OUT
DWord
Contains the error information of DPWR_DAT (Page 408) in the form
DW#16#40xxxx00, if ERROR = TRUE
ERROR
OUT
Bool
Error display: ERROR = TRUE if an error occurs when DPWR_DAT
(Page 408) is called
OUTPUTS
IN_OUT
Variant
Source range for the data to be written: If the source area is greater than
LEN, the first LEN bytes are transferred from OUTPUTS.
You can use the following data types:
•
1
System data types and array of system data types: BYTE, CHAR,
SINT, USINT, WORD, INT, UINT, DWORD, DINT, UDINT, REAL,
LREAL, LWORD, LINT, ULINT
•
User Defined Types (UDT)
•
Structures (STRUCT), but only in non-optimized data blocks (DB)
When displaying the SETIO_PART error codes, use the DWord data type.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
393
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.7
RALRM (Receive interrupt)
You can use the RALRM (Read alarm) instruction with PROFINET and PROFIBUS.
Table 9- 81
RALRM instruction
LAD / FBD
SCL
"RALRM_DB"(
mode:=_int_in_,
f_ID:=_word_in_,
mlen:=_uint_in_,
new=>_bool_out_,
status=>_dword_out_,
ID=>_word_out_,
len=>_uint_out_,
tinfo:=_variant_inout_,
ainfo:=_variant_inout_);
Description
Use the RALRM (read alarm) instruction to read diagnostic
interrupt information from PROFIBUS or PROFINET I/O modules/devices.
The information in the output parameters contains the start
information of the called OB as well as information of the interrupt source.
Call RALRM in an interrupt OB to return information regarding
the event(s) that caused the interrupt. In the S7-1200. The following Diagnostic OB interrupts are supported: Status, Update,
Profile, Diagnostic error interrupt, Pull or plug of modules, Rack
or station failure.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "RALRM_DB" is the name of the instance DB.
Table 9- 82
Data types for the parameters
Parameter and type
Data type
Description
MODE
IN
Byte, USInt, SInt, Int
Operating mode
F_ID
IN
HW_IO (Word)
Logical start address of the component (module) from which interrupts
are to be received
Note: The device ID can be determined in one of two ways:
•
•
By making the following "Network view" selections:
–
Device (gray box)
–
"Properties" of the device
–
"Hardware identifier"
Note: Not all devices display their Hardware identifiers.
By making the following "Project tree" menu selections:
–
PLC tags
–
Default tag table
–
System constants tab
–
All configured device Hardware identifiers are displayed.
MLEN
IN
Byte, USInt, UInt
Maximum length in bytes of the data interrupt information to be received. MLEN of 0 will allow receipt of as much data interrupt information as is available in the AINFO Target Area.
NEW
OUT
Bool
A new interrupt was received.
STATUS
OUT
DWord
Status of the RALRM instruction. Refer to "STATUS parameter for
RDREC, WRREC, and RALRM" (Page 403) for more information.
S7-1200 Programmable controller
394
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameter and type
Data type
Description
ID
HW_IO (Word)
Hardware identifier of the I/O module that caused the diagnostic interrupt
OUT
Note: Refer to the F_ID parameter for an explanation of how to determine the device ID.
LEN
OUT
DWord, UInt, UDInt,
DInt, Real, LReal
Length of the received AINFO interrupt information
TINFO
IN_OUT
Variant
Task information: Target range for OB start and management information. The TINFO length is always 32 bytes.
AINFO
IN_OUT
Variant
Interrupt information: Target area for header information and additional
interrupt information. For AINFO, provide a length of at least the MLEN
bytes, if MLEN is greater than 0. The AINFO length is variable.
Note
If you call "RALRM" in an OB whose start event is not an I/O interrupt, the instruction will
provide correspondingly reduced information in its outputs.
Make sure to use different instance DBs when you call "RALRM" in different OBs. If you
evaluate data from an "RALRM" call outside of the associated interrupt OB, use a separate
instance DB per OB start event.
Note
The interface of the "RALRM" instruction is identical to the "RALRM" FB defined in
"PROFIBUS Guideline PROFIBUS Communication and Proxy Function Blocks according to
IEC 61131-3".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
395
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Calling RALRM
You can call the RALRM instruction in three different operating modes (MODE).
Table 9- 83
RALRM instruction operating modes
MODE
Description
0
•
1
2
ID contains the hardware identifier of the I/O module that triggered the interrupt.
•
Output parameter NEW is set to TRUE.
•
LEN produces an output of 0.
•
AINFO and TINFO are not updated with any information.
•
ID contains the hardware identifier of the I/O module that triggered the interrupt.
•
Output parameter NEW is set to TRUE.
•
LEN produces an output of the amount in bytes of AINFO data that is returned.
•
AINFO and TINFO are updated with interrupt-related information.
If the hardware identifier assigned to input parameter F_ID has triggered the interrupt then:
•
ID contains the hardware identifier of the I/O module that triggered the interrupt. Should be the same
as the value at F_ID.
•
Output parameter NEW is set to TRUE.
•
LEN produces an output of the amount in bytes of AINFO data that is returned.
•
AINFO and TINFO are updated with interrupt-related information.
Note
If you assign a destination area for TINFO or AINFO that is too short, RALRM cannot return
the full information.
MLEN can limit the amount of AINFO data that is returned.
Refer to the AINFO parameters and TINFO parameters of the online information system of
STEP 7 for information on how to interpret the TINFO and AINFO data.
S7-1200 Programmable controller
396
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
TInfo organization block data
The table below shows how the TInfo data is arranged for the RALRM instruction:
Same for OBs: Status, Update, Profile,
Diagnostic error interrupt, Pull or plug of
modules, Rack or station failure
0
4
TI_Submodule - OBs: Status, Update,
Profile
LADDR
Slot
Specifier
Channel
4
MultiError
0
Event_Class
Fault_ID
0
0
4
Event_Class
8
Same for OBs: Status, Update, Profile,
Diagnostic error interrupt, Pull or plug of
modules, Rack or station failure
0
IO_State
8
TI_StationFailure - OB: Rack or station
failure
OB_Nr
4
8
TI_PlugPullModule - OB: Pull or plug of
modules
OB_Class
4
8
TI_DiagnosticInterrupt - OB: Diagnostic
error interrupt
SI_Format
0
Fault_ID
0
12
0
16
20
24
281
1
address
flags1
flags2
manufacturer
slv_prfl
intr_type
id
instance
Bytes 28 - 31 (manufacturer and instance) are not used with PROFIBUS.
Note
Refer to the online information system of STEP 7 for more detailed information on TINFO
data.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
397
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.8
D_ACT_DP (Enable/disable PROFINET IO devices)
With the "D_ACT_DP" instruction, you can disable and enable configured PROFINET IO
devices in a targeted manner. In addition, you can determine whether each assigned
PROFINET IO device is currently activated or deactivated.
Note
You can only use the D_ACT_DP instruction with PROFINET IO devices. You cannot use
the instruction with PROFIBUS DP slaves.
Table 9- 84
D_ACT_DP instruction
LAD / FBD
SCL
"D_ACT_DP_DB"(
req:=_bool_in_,
mode:=_usint_in_,
laddr:=_uint_in_,
ret_val=>_int_out_,
busy=>_bool_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "D_ACT_DP_SFB_DB" is the name of the instance DB.
Description
Use the D_ACT_DP instruction to
disable and enable configured
PROFINET IO devices and determine
whether each assigned PROFINET
IO device is currently activated or
deactivated.
You cannot disable/enable an IE/PB Link PN IO type of gateway using the D_ACT_DP
instruction. If you nevertheless use D_ACT_DP on the gateway named, the CPU returns the
value W#16#8093 (there is no hardware object that can be activated or deactivated for the
address specified in LADDR).
Note
The disabling or enabling job requires several runs through the cycle control point.
Therefore, you cannot wait for the end of such a job in a programmed loop.
Functional description
D_ACT_DP is an asynchronous instruction, which means that the job processing extends
over multiple D_ACT_DP instruction executions. You start the job by calling D_ACT_DP with
REQ = 1.
The output parameters RET_VAL and BUSY indicate the status of the job.
Application
If you configure PROFINET IO devices in a CPU which are not actually present or not
currently required, the CPU nevertheless continues to access these PROFINET IO devices
at regular intervals. After the devices are deactivated, further CPU accessing stops. The
corresponding error events no longer occur.
S7-1200 Programmable controller
398
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Examples
From a machine OEM's point of view, there are numerous device options possible in series
production of machines. However, each delivered machine includes only one combination of
selected options.
The manufacturer configures every one of these possible machine options as a PROFINET
IO device. The manufacturer does this in order to create and maintain a common user
program having all possible options. Use D_ACT_DP to deactivate all PROFINET IO devices
not present at machine startup.
A similar situation exists for machine tools having numerous tooling options available, but
actually using only a few of them at any given time. These tools are implemented as
PROFINET IO devices. With D_ACT_DP, the user program activates the tools currently
needed and deactivates those required later.
Identification of a job
If you have started a deactivation or activation job and you call D_ACT_DP again before the
job is complete, the behavior of the instruction depends on whether or not the new call
involves the same job. If the input parameter LADDR matches, the call is interpreted as a
follow-on call.
Deactivating PROFINET IO devices
When you deactivate a PROFINET IO device with D_ACT_DP, its process outputs are set to
the configured substitute values or to "0" (safe state). The assigned PROFINET IO controller
does not continue to address this component. The error LEDs on the PROFINET IO
controller or CPU do not identify the deactivated PROFINET IO devices as faulty or missing.
The CPU updates the process image inputs of deactivated PROFINET IO devices with "0".
Therefore, the CPU treats the deactivated PROFINET IO devices just like failed PROFINET
IO devices.
If you directly access the user data of a previously deactivated PROFINET IO device from
your program, the system behavior depends on the block’s error handling selection:
● If global error handling is enabled, the system enters an access error start event into the
diagnostic buffer and stays in RUN.
● If block-local error handling is enabled, the system enters an error cause in the error
structure. You can access the error cause using the GET_ERROR_ID (Page 311)
instruction.
An error for a read access returns "0". Refer to "Event execution priorities and queuing"
(Page 105) for further information on error handling.
If you attempt to access a deactivated PROFINET IO device using an instruction (such as
"RD_REC (Page 385)"), you receive the same error information in RET_VAL as for an
unavailable PROFINET IO device.
If a PROFINET IO station fails after you have deactivated it with D_ACT_DP, the operating
system does not detect the failure.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
399
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Activating PROFINET IO devices
When you reactivate a PROFINET IO device with D_ACT_DP, the associated PROFINET IO
controller configures the component and assigns parameters (as with the return of a failed
PROFINET IO station). This activation is complete when the component is able to transfer
user data.
If you try to activate a PROFINET IO device that cannot be accessed (for example, because
it was physically separated from the bus) with a D_ACT_DP instruction, the instruction
returns the error code W#16#80A7 after expiration of the configured parameter assignment
time for distributed I/O. The PROFINET IO device is activated and the fact that the activated
PROFINET IO device cannot be accessed results in a corresponding display in the system
diagnostics.
If the PROFINET IO device is accessible again afterwards, this results in standard system
behavior.
Note
Activating a PROFINET IO device can be time-consuming. If you want to cancel a currently
running activation job, start D_ACT_DP with the same value for LADDR and MODE = 2. You
repeat the call for D_ACT_DP with MODE = 2 until the successful cancellation of the
activation job is displayed with RET_VAL = 0.
Parameters
The following table shows the parameters of the D_ACT_DP instruction:
Parameter Declaration
Data type
Description
REQ
Bool
Level-triggered control parameter
IN
REQ = 1: Run activation or deactivation
MODE
LADDR
IN
IN
USInt
HW_DEVICE
Job identifier
Possible values:
•
0: Request information on whether the addressed component
is activated or deactivated (output using RET_VAL parameter)
•
1: Activate the PROFINET IO device
•
2: Deactivate the PROFINET IO device
Hardware identifier of the PROFINET IO device (HW_Device)
The number can be taken from the properties of the PROFINET IO
device in the Network view or from the "System constants" tab of
the standard tag table.
If both the identifier for the device diagnostics as well as the ID for
operating state transitions are specified there, you must use the
code for the device diagnostics.
S7-1200 Programmable controller
400
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameter Declaration
Data type
Description
RET_VAL
OUT
Int
If an error occurs while the program executes the instruction, the
return value contains an error code.
BUSY
OUT
Bool
Active code:
•
BUSY = 1: The job is still active.
•
BUSY = 0: The job was terminated.
Parameter RET_VAL
Error code*
Explanation
(W#16#...)
0000
Job completed without error.
0001
The PROFINET IO device is active (this error code is only possible with MODE = 0.)
0002
The PROFINET IO device is deactivated (this error code is only possible with
MODE = 0.)
7000
First call with REQ = 0: The job specified in LADDR is not active; BUSY has the value
"0".
7001
First call with REQ = 1. The program triggered the job specified in LADDR. BUSY has
the value "1".
7002
Intermediate call (REQ irrelevant). The activated job is still active; BUSY has the value "1".
8090
•
You have not configured a module with the address specified in LADDR.
•
You operate your CPU as I-slave / I-device, and you have specified an address of
this I-slave/I-device in LADDR.
8092
The deactivation of the currently addressed PROFINET IO device (MODE = 2) cannot
be canceled by being activated (MODE = 1). Activate the component at a later time.
8093
The address specified in LADDR does not belong to any PROFINET IO device that
can be activated or deactivated, or the MODE parameter is unknown.
8094
You have attempted to activate a device which is a potential partner for a tool change
port. However, another device is already activated on this tool change port at this
time. The activated device remains activated.
80A0
Error during the communication between the CPU and the IO controller.
80A1
Parameters cannot be assigned for the addressed component. (This error code is
only possible when MODE = 1.)
Note: If this component fails again during parameter assignment of the activated device, the D_ACT_DP instruction supplies the error information. If the parameter assignment of a single module is unsuccessful, D_ACT_DP returns the error information
W#16#0000.
80A3
The PROFINET IO controller concerned does not support this function.
80A4
The CPU does not support this function for an external PROFINET IO controller.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
401
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Error code*
Explanation
(W#16#...)
80A6
Slot error in the PROFINET IO device; not all user data can be accessed (this error
code is only available when MODE = 1).
Note: D_ACT_DP returns this error information only if the activated component fails
again after parameter assignment and before the end of the D_ACT_DP instruction
execution. If only a single module is unavailable, D_ACT_DP returns the error information W#16#0000.
80A7
A timeout occurred during activation: The remote device is unreachable, or you have
set the parameter assignment time for central and distributed I/O too short. The status
of the remote device is "activated", but it is not accessible.
80AA
Activation with errors in the PROFINET IO device: Differences in the configuration
80AB
Activation with errors in the PROFINET IO device: Parameter assignment error
80AC
Activation with errors in the PROFINET IO device: Maintenance required
80C1
D_ACT_DP has started and is being continued with another address (this error code
is possible when MODE = 1 and MODE = 2).
80C3
•
Temporary resource error: The CPU is currently processing the maximum possible
activation and deactivation jobs (8). (This error code is only possible when
MODE = 1 and MODE = 2.)
•
The CPU is busy receiving a modified configuration. Currently, you cannot enable/disable PROFINET IO devices.
80C6
PROFINET: Jobs not collected by the user are discarded at restart.
General error See the GET_ERROR_ID (Page 311) instruction for information on how to access the
information
error.
* The error codes in the program editor can be displayed as integer or hexadecimal values.
S7-1200 Programmable controller
402
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.9
STATUS parameter for RDREC, WRREC, and RALRM
The output parameter STATUS contains error information that is interpreted as ARRAY[1...4]
OF BYTE, with the following structure:
Table 9- 85
STATUS output array
Array element
Name
Description
STATUS[1]
Function_Num
•
B#16#00, if no error
•
Function ID from DPV1-PDU: If an error occurs, B#16#80 is OR'ed (for read
data record: B#16#DE; for write data record: B#16#DF). If no DPV1 protocol
element is used, then B#16#C0 will be output.
STATUS[2]
Error_Decode
Location of the error ID
STATUS[3]
Error_Code_1
Error ID
STATUS[4]
Error_Code_2
Manufacturer-specific error ID expansion
Table 9- 86
STATUS[2] values
Error_decode
(B#16#....)
Source
Description
00 to 7F
CPU
No error or no warning
80
DPV1
Error according to IEC 61158-6
81 to 8F
CPU
B#16#8x shows an error in the "xth" call parameter of the instruction.
FE, FF
DP Profile
Profile-specific error
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
403
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Table 9- 87
STATUS[3] values
Error_decode
(B#16#....)
Error_code_1
(B#16#....)
00
00
70
00
Reserved, reject
Initial call; no active data record transfer
01
Reserved, reject
Initial call; data record transfer has started
02
Reserved, reject
Intermediate call; data record transfer already active
90
Reserved, pass
Invalid logical start address
92
Reserved, pass
Illegal type for Variant pointer
93
Reserved, pass
The DP component addressed via ID or F_ID is not configured.
80
Explanation (DVP1)
Description
No error, no warning
96
The "RALRM (Page 394)" cannot supply the OB start
information, management information, header information, or additional interrupt information.
For the following OBs, you can use the "DPNRM_DG
(Page 416)" instruction to read the current diagnostics
message frame of the relevant DP slave asynchronously
(address information from OB start information):
•
Hardware interrupt (Page 95)
•
Status (Page 102), Update (Page 103) or Profile
(Page 103)
•
Diagnostic error interrupt (Page 97)
•
Pull or plug of modules (Page 100)
A0
Read error
Negative acknowledgement while reading from the module
A1
Write error
Negative acknowledgement while writing to the module
A2
Module failure
DP protocol error at layer 2 (for example, slave failure or
bus problems)
A3
Reserved, pass
•
PROFIBUS DP: DP protocol error with Direct-DataLink-Mapper or User-Interface/User
•
PROFINET IO: General CM error
A4
Reserved, pass
Communication on the communication bus disrupted
A5
Reserved, pass
-
A7
Reserved, pass
DP slave or modules is occupied (temporary error).
A8
Version conflict
DP slave or module reports non-compatible versions.
A9
Feature not supported
Feature not supported by DP slave or module
AA to AF
User specific
DP slave or module reports a manufacturer-specific error
in its application. Please check the documentation from
the manufacturer of the DP slave or module.
B0
Invalid index
Data record not known in module; illegal data record
number ≥ 256
S7-1200 Programmable controller
404
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Error_decode
(B#16#....)
Error_code_1
(B#16#....)
Explanation (DVP1)
Description
B1
Write length error
The length information in the RECORD parameter is
incorrect.
•
With "RALRM": Length error in AINFO
Note: Refer to the online information system of
STEP 7 for immediate access to information on how
to interpret the "AINFO" returned buffers.
•
With "RDREC (Page 385)" and "WRREC
(Page 385)": Length error in "MLEN"
B2
Invalid slot
The configured slot is not occupied.
B3
Type conflict
Actual module type does not match specified module
type.
B4
Invalid area
DP slave or module reports access to an invalid area.
B5
Status conflict
DP slave or module not ready
B6
Access denied
DP slave or module denies access.
B7
Invalid range
DP slave or module reports an invalid range for a parameter or value.
B8
Invalid parameter
DP slave or module reports an invalid parameter.
B9
Invalid type
DP slave or module reports an invalid type:
•
With "RDREC (Page 385)": Buffer too small (subsets
cannot be read)
•
With "WRREC (Page 385)": Buffer too small (subsets
cannot be written)
BA to BF
User specific
DP slave or module reports a manufacturer-specific error
when accessing. Please check the documentation from
the manufacturer of the DP slave or module.
C0
Read constraint conflict •
•
With "WRREC (Page 385)": The data can only be
written when the CPU is in STOP mode.
Note: This means that data cannot be written by the
user program. You can only write the data online with
a PG/PC.
With "RDREC (Page 385)": The module routes the
data record, but either no data is present or the data
can only be read when the CPU is in STOP mode.
Note: If data can only be read when the CPU is in
STOP mode, no evaluation by the user program is
possible. In this case, you can only read the data
online with a PG/PC.
C1
Write constraint conflict The data of the previous write request to the module for
the same data record has not yet been processed by the
module.
C2
Resource busy
The module is currently processing the maximum possible number of jobs for a CPU.
C3
Resource unavailable
The required operating resources are currently occupied.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
405
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Error_decode
(B#16#....)
Error_code_1
(B#16#....)
Description
C4
Internal temporary error. Job could not be carried out.
Repeat the job. If this error occurs often, check your
installation for sources of electrical interference.
C5
DP slave or module not available
C6
Data record transfer was cancelled due to priority class
cancellation.
C7
Job aborted due to warm or cold restart on the DP master.
C8 to CF
DP slave or module reports a manufacturer-specific resource error. Please check the documentation from the
manufacturer of the DP slave or module.
Dx
81
Explanation (DVP1)
User specific
DP Slave specific. Refer to the description of the DP
Slave.
00 to FF
Error in the initial call parameter (with "RALRM
(Page 394)": MODE)
00
Illegal operating mode
82
00 to FF
Error in the second call parameter
88
00 to FF
Error in the eighth call parameter (with "RALRM
(Page 394)": TINFO)
Note: Refer to the online information system of STEP 7
for immediate access to information on how to interpret
the "TINFO" returned buffers.
89
01
Wrong syntax ID
23
Quantity structure exceeded or destination area too small
24
Wrong range ID
32
DB/DI number out of user range
3A
DB/DI number is NULL for area ID DB/DI, or specified
DB/DI does not exist.
00 to FF
Error in the ninth call parameter (with "RALRM
(Page 394)": AINFO)
Note: Refer to the online information system of STEP 7
for immediate access to information on how to interpret
the "AINFO" returned buffers.
01
Wrong syntax ID
23
Quantity structure exceeded or destination area too small
24
Wrong range ID
32
DB/DI number out of user range
3A
DB/DI number is NULL for area ID DB/DI, or specified
DB/DI does not exist.
8A
00 to FF
Error in the 10th call parameter
8F
00 to FF
Error in the 15th call parameter
FE, FF
00 to FF
Profile-specific error
S7-1200 Programmable controller
406
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Array element STATUS[4]
With DPV1 errors, the DP Master passes on STATUS[4] to the CPU and to the instruction.
Without a DPV1 error, this value is set to 0, with the following exceptions for the RDREC:
● STATUS[4] contains the target area length from RECORD, if MLEN > the destination
area length from RECORD.
● STATUS[4]=MLEN, if the actual data record length < MLEN < the destination area length
from RECORD.
● STATUS[4]=0, if STATUS[4] > 255; would have to be set
In PROFINET IO, STATUS[4] has the value 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
407
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.10
Others
9.3.10.1
DPRD_DAT and DPWR_DAT (Read/write consistent data)
Use the DPRD_DAT (Read consistent data) instruction to read one or more bytes of data
consistently, and use the DPWR_DAT (Write consistent data) instruction to transfer one or
more bytes of data consistently. You can use the DPRD_DAT and DPWR_DAT instructions
with PROFINET and PROFIBUS.
Table 9- 88
LAD / FBD
DPRD_DAT and DPWR_DAT instructions
SCL
ret_val := DPRD_DAT(
laddr:=_word_in_,
record=>_variant_out_);
ret_val := DPWR_DAT(
laddr:=_word_in_,
record:=_variant_in_);
Description
Use the DPRD_DAT instruction to read one or more
bytes of data from modules or submodules of one of
the following locations:
•
Local base I/O
•
DP slave
• PROFINET I/O device
The CPU transfers the data read consistently. If no
errors occur during the data transfer, the CPU enters
the read data into the target area set up by the
RECORD parameter. The target area must have the
same length as you configured with STEP 7 for the
selected module. When you execute the DPRD_DAT
instruction, you can only access the data of one
module or submodule. The transfer starts at the
configured start address.
Use the DPWR_DAT instruction to transfer the data
in RECORD consistently to the following locations:
•
Addressed module or submodule in the local
base
•
DP standard slave
• PROFINET I/O device
The source area must have the same length as you
configured with STEP 7 for the selected module or
submodule.
● The S7-1200 CPU supports consistent peripheral I/O read or write of 1, 2, or 4 bytes. Use
the DPRD_DAT instruction to consistently read and the DPWR_DAT instruction to
consistently write data of lengths other than 1, 2, or 4 bytes.
● You can use these instructions for data areas of 1 or more bytes. If the access is rejected,
error code W#16#8090 results.
● PROFINET supports up to 1024 bytes of consistent data. You do not need to use these
instructions for consistent transfers between the S7-1200 and PROFINET devices.
S7-1200 Programmable controller
408
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Note
If you are using the DPRD_DAT and DPWR_DAT instructions with consistent data, you must
remove this consistent data from the process-image automatic update. Refer to "PLC
concepts: Execution of the user program" (Page 83) for more information.
Table 9- 89
Parameters
Parameter
Declaration
Data type
Description
LADDR
IN
HW_IO (Word) Hardware ID of the module from which the data is to be read.
(DPRD_DAT)
Hardware ID of the module to which the data is to be written.
(DPWR_DAT)
The hardware ID can be found in the properties of the module in the device
view or system constants.
RECORD
OUT
Variant
Destination area for the user data that were read (DPRD_DAT) or source
area for the user data to be written (DPWR_DAT). This must be exactly as
large as you configured for the selected module with STEP 7.
RET_VAL
OUT
Int
If an error occurs while the function is active, the return value contains an
error code.
DPRD_DAT operations
Use the parameter LADDR to select the module of the DP standard slave / PROFINET IO
device. If an access error occurs on the addressed module, the error code W#16#8090 is
output.
Use the parameter RECORD to define the target range of the read data:
● The target range has to be at least as long as the inputs of the selected module. Only the
inputs are transferred; the other bytes are not considered. If you read from a DP standard
slave with a modular configuration or with several DP identifiers, you can only access the
data of a module of the configured hardware identifier for each DPRD_DAT instruction
call. If you select a target range that is too small, the error code W#16#80B1 is output at
the RET_VAL parameter.
● The following data types can be used: Byte, Char, Word, DWord, Int, UInt, USInt, SInt,
DInt, UDInt. The use of these data types in a User Defined Type (UDT) data structure of
the type ARRAY or STRUCT is permissible.
● The data type STRING is not supported.
● If there was no error during the data transmission, the data that have been read are
entered in the target range defined at the parameter RECORD.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
409
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
DPWR_DAT operations
Use the parameter LADDR to select the module of the DP standard slave / PROFINET IO
device. If an access error occurs on the addressed module, the error code W#16#8090 is
output.
Use the parameter RECORD to define the source range of the data to be written:
● The source range has to be at least as long as the outputs of the selected module. Only
the outputs are transferred; the other bytes are not considered. If the source range at the
parameter RECORD is longer than the outputs of the configured module, only the data up
to the maximum length of the outputs is transferred. If the source range at the parameter
RECORD is shorter than the outputs of the configured module, the error code
W#16#80B1 is output at the RET_VAL parameter.
● The following data types can be used: Byte, Char, Word, DWord, Int, UInt, USInt, SInt,
DInt, UDInt. The use of these data types in a User Defined Type (UDT) data structure of
the type ARRAY or STRUCT is permissible.
● The data type STRING is not supported.
● The data is transferred synchronously, that is, the write process is completed when the
instruction is completed.
Error codes
Table 9- 90
1
DPRD_DAT and DPWR_DAT error codes
Error code 1
Description
0000
No error occurred
8090
One of the following cases apply:
•
You have not configured a module for the specified logical base address.
•
You have ignored the restriction concerning the length of consistent data.
•
You have not entered the start address in the LADDR parameter in hexadecimal format.
8092
The RECORD parameter supports the following data types: Byte, Char, Word, DWord, Int, UInt,
USInt, SInt, DInt, UDInt, and arrays of these types.
8093
No DP module/PROFINET IO device from which you can read (DPRD_DAT) or to which you can
write (DPWR_DAT) consistent data exists at the logical address specified in LADDR.
80A0
Access error detected while the I/O devices were being accessed (DPRD_DAT).
80B1
The length of the specified destination (DPRD_DAT) or source (DPWR_DAT) area is not identical to
the user data length configured with STEP 7 Basic.
80B2
System error with external DP interface module (DPRD_DAT) and (DPWR_DAT)
When displaying the DPRD_DAT and DPWR_DAT error codes, use the Word data type.
Note
If you access DPV1 slaves, error information from these slaves can be forwarded from the
DP master to the instruction.
S7-1200 Programmable controller
410
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
9.3.10.2
RCVREC (I-device/I-slave receive data record)
An I-device can receive a data record from a higher-level controller. The receipt takes place
in the user program with the RCVREC instruction (receive data record).
Table 9- 91
RCVREC instruction
LAD / FBD
SCL
"RCVREC_SFB_DB"(
mode:=_int_in_,
F_ID:=_uint_in_,
mlen:=_uint_in_,
code1:=_byte_in_,
code2:=_byte_in_,
new=>_bool_out_,
status=>_dword_out_,
slot=>_uint_out_,
subslot=>_uint_out_,
index=>_uint_out_
len=>_uint_out_,
record:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "RCVREC_SFB_DB" is the name of the instance DB.
Description
Use the RCVREC instruction to receive a data record from a higherlevel controller.
The instruction has the following operating modes:
● Check whether the I-device has a request for a data record receipt
● Make the data record available to the output parameters
● Send an answer to the higher-level controller
You can determine the operating mode executed by the instruction using the input parameter
MODE (see below).
The I-device must be in the RUN or STARTUP mode.
With MLEN, you specify the maximum number of bytes you want to receive. The selected
length of the target range RECORD should have at least the length of MLEN bytes.
If a data record is received (MODE = 1 or MODE = 2), the output parameter NEW indicates
that the data record is stored in RECORD. Note that RECORD has a sufficient length. The
output parameter LEN contains the actual length of the data record received in bytes.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
411
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Set CODE1 and CODE2 to zero for the positive answer to the higher-level controller. If the
received data record is to be rejected, enter the negative answer to the higher-level
controller in Error Code 1 of the CODE1 and in Error Code 2 of the CODE2.
Note
If the I-device has received a request for a data record receipt, you must recognize the
delivery of this request within a certain duration. After recognition, you must send an answer
to the higher-level controller within this time period. Otherwise, the I-device experiences a
timeout error which causes the operating system of the I-device to send a negative answer
to the higher-level controller. For information on the value for the time period, refer to the
specifications of your CPU.
The STATUS output parameter receives the error information after the occurrence of an
error.
Operating modes
You can determine the operating mode of the RCVREC instruction with the input parameter
MODE. This step is explained in the following table:
MODE
0
Meaning
Check whether a request for a data record receipt exists
If a data record from a higher-level controller exists on the I-device, the instruction only writes to the NEW,
SLOT, SUBSLOT, INDEX, and LEN output parameters. If you call the instruction several times with MODE =
0, then the output parameter only refers to one and the same request.
1
Receiving a data record for any subslot of the I-device
If a data record from a higher-level controller exists on the I-device for any subslot of the I-device, the instruction writes to the output parameter and transfers the data record to the parameter RECORD.
2
Receiving a data record for a specific subslot of the I-device
If a data record from a higher-level controller exists on the I-device for a specific subslot of the I-device, the
instruction writes to the output parameter and transfers the data record to the parameter RECORD.
3
Sending a positive answer to the higher-level controller
The instruction checks the request of the higher-level controller to receive a data record, accepts the existing
data record, and sends a positive acknowledgment to the higher-level controller.
4
Sending a negative answer to the higher-level controller
The instruction checks the request of the higher-level controller to receive a data record, rejects the existing
data record, and sends a negative acknowledgment to the higher-level controller. Enter the reason for the
rejection in the input parameters CODE1 and CODE2.
Note
After the receipt of a data record (NEW = 1), you must call the RCVREC instruction twice to
ensure complete processing. You must do this in the following order:
• First call with MODE = 1 or MODE = 2
• Second call with MODE = 3 or MODE = 4
S7-1200 Programmable controller
412
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameters
The following table shows the parameters of the RCVREC instruction:
Parameter Declaration
Data type
Description
MODE
IN
Int
Mode
F_ID
IN
HW_SUBMODULE
Subslot in the transfer area of the I-device for the data record to
be received (only relevant for MODE = 2). The high word is always
set to zero.
MLEN
IN
Int
Maximum length of the data record to be received in bytes
CODE1
IN
Byte
Zero (for MODE = 3) and/or Error Code 1 (for MODE = 4)
CODE2
IN
Byte
Zero (for MODE = 3) and/or Error Code 2 (for MODE = 4)
NEW
OUT
Bool
•
MODE = 0: New data record was received
•
MODE = 1 or 2: Data record was transferred to RECORD
STATUS
OUT
DWord
Error information. Refer to "STATUS parameter" (Page 403) for
more information.
SLOT
OUT
HW_SUBMODULE
Identical to F_ID
SUBSLOT OUT
HW_SUBMODULE
Identical to F_ID
INDEX
OUT
UInt
Number of the data record received
LEN
OUT
UInt
Length of the data record received
RECORD
IN_OUT
Variant
Target range for the data record received
9.3.10.3
PRVREC (I-device/I-slave make data record available)
An I-device can receive a request from a higher-level controller to make a data record
available. The I-device makes the data record available in the user program with the
PRVREC instruction (make data record available).
Table 9- 92
PRVREC instruction
LAD / FBD
SCL
"PRVREC_SFB_DB"(
mode:=_int_in_,
F_ID:=_uint_in_,
code1:=_byte_in_,
code2:=_byte_in_,
len:=_uint_in_,
new=>_bool_out_,
status=>_dword_out_,
slot=>_uint_out_,
subslot=>_uint_out_,
index=>_uint_out_
rlen=>_uint_out_,
record:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "PRVREC_SFB_DB" is the name of the instance DB.
Description
Use the PRVREC instruction to receive a request from a higher-level
controller to make a data record
available.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
413
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
The instruction has the following operating modes:
● Check whether the I-device has a request for making a data record available
● Transfer the requested data record to the higher-level controller
● Sending an answer to the higher-level controller
You can determine the operating mode executed by the instruction using the input parameter
MODE (see below).
The I-device must be in the RUN or STARTUP mode.
Enter the maximum number of bytes the data record to be sent should have with LEN. The
selected length of the target range RECORD should have at least the length of LEN bytes.
If a request to make a data record available exists, (MODE = 0), the output parameter NEW
is set to TRUE.
If the request for making a data record available is accepted, write RECORD for the positive
answer to the higher-level controller with the requested data record and write zero for
CODE1 and CODE2. If the request for making a data record available is to be rejected, enter
the negative answer to the higher-level controller in Error Code 1 of the CODE1 and in Error
Code 2 of the CODE2.
Note
If the I-device has received a request for making a data record available, you must recognize
the delivery of this request within a certain time period. After recognition, you must send an
answer to the higher-level controller within this time period. Otherwise, the I-device
experiences a timeout error which causes the operating system of the I-device to send a
negative answer to the higher-level controller. For information on the value for the time
period, refer to the specifications of your CPU.
The STATUS output parameter receives the error information after the occurrence of an
error.
S7-1200 Programmable controller
414
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Operating modes
You can determine the operating mode of the PRVREC instruction with the input parameter
MODE. This step is explained in the following table:
MODE
Meaning
0
Check whether a request for making a data record available exists
If a request from a higher-level controller for making a data record available exists on the I-device, the instruction only writes to the NEW, SLOT, SUBSLOT, INDEX, and RLEN output parameters. If you call the instruction
several times with MODE = 0, then the output parameter only refers to one and the same request.
1
Receiving a request for making a data record available for any subslot of the I-device
If such a request from a higher-level controller for any subslot of the I-device exists on the I-device, the instruction writes to the output parameter.
2
Receiving a request for making a data record available for a specific subslot of the I-device
If such a request from a higher-level controller for a specific subslot of the I-device exists on the I-device, the
instruction writes to the output parameter.
3
Make the data record available and send a positive answer to the higher-level controller
The instruction checks the request of the higher-level controller to make a data record available, makes the
request data record available to RECORD, and sends a positive acknowledgement to the higher-level controller.
4
Sending a negative answer to the higher-level controller
The instruction checks the request of the higher-level controller to make a data record available, rejects this
request, and sends a negative acknowledgement to the higher-level controller. Enter the reason for the rejection in the input parameters CODE1 and CODE2.
Note
After the receipt of a request (NEW = 1), you must call the PRVREC instruction twice to
ensure complete processing. You must do this in the following order:
• First call with MODE = 1 or MODE = 2
• Second call with MODE = 3 or MODE = 4
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
415
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Parameters
The following table shows the parameters of the PRVREC instruction:
Parameter Declaration
Data type
Description
MODE
IN
Int
Mode
F_ID
IN
HW_SUBMODULE
Subslot in the transfer area of the I-device for the data record to be
sent (only relevant for MODE = 2). The high word is always set to
zero.
CODE1
IN
Byte
Zero (for MODE = 3) and/or Error Code 1 (for MODE = 4)
CODE2
IN
Byte
Zero (for MODE = 3) and/or Error Code 2 (for MODE = 4)
LEN
IN
UInt
Maximum length of the data record to be sent in bytes
NEW
OUT
Bool
The new data record was requested by the higher-level controller.
STATUS
OUT
DWord
Error information. Refer to "STATUS parameter" (Page 403) for
more information.
SLOT
OUT
HW_SUBMODULE
Identical to F_ID
SUBSLOT OUT
HW_SUBMODULE
Identical to F_ID
INDEX
OUT
UInt
Number of the data record to be sent
RLEN
OUT
UInt
Length of the data record to be sent
RECORD
IN_OUT
Variant
Data record made available
9.3.10.4
DPNRM_DG (Read diagnostic data from a PROFIBUS DP slave)
You can use the DPNRM_DG (Read diagnostic data) instruction with PROFIBUS.
Table 9- 93
LAD / FBD
DPNRM_DG instruction
SCL
ret_val := DPNRM_DG(
req:=_bool_in_,
laddr:=_word_in_,
record=>_variant_out_,
busy=>_bool_out_);
Description
Use the DPNRM_DG instruction to read the current diagnostic data of
a DP slave in the format specified by EN 50 170 Volume 2,
PROFIBUS. The data that has been read is entered in the destination
area indicated by RECORD following error-free data transfer.
S7-1200 Programmable controller
416
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Table 9- 94
DPNRM_DG instruction data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
REQ=1: Read request
LADDR
IN
HW_DPSLAVE
Configured diagnostic address of the DP slave: Must be the address of
the station and not for the I/O device. Select the station (and not the
image of the device) in the "Network" view of the "Device configuration"
to determine the diagnostic address.
Enter the addresses in hexadecimal format. For example, diagnostic
address 1022 means LADDR:=W#16#3FE.
RET_VAL
OUT
Int
If an error occurs while the function is active, the return value contains
an error code. If no error occurs, the length of the data actually transferred is entered in RET_VAL.
RECORD
OUT
Variant
Destination area for the diagnostic data that were read. The minimum
length of the data record to be read (or the destination area) is 6 bytes.
The maximum length of the data record to be sent is 240 bytes.
Standard slaves can provide more than 240 bytes of diagnostic data up
to a maximum of 244 bytes. In this case, the first 240 bytes are transferred to the destination area, and the overflow bit is set in the data.
BUSY
OUT
Bool
BUSY=1: The read job is not yet completed
You start the read job by assigning 1 to the input parameter REQ in the DPNRM_DG
instruction call. The read job is executed asynchronously, in other words, it requires several
DPNRM_DG instruction calls. The status of the job is indicated by the output parameters
RET_VAL and BUSY.
Table 9- 95
Slave diagnostic data structure
Byte
Description
0
Station status 1
1
Station status 2
2
Station status 3
3
Master station number
4
Vendor ID (high byte)
5
Vendor ID (low byte)
6 ...
Additional slave-specific diagnostic information
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
417
Extended instructions
9.3 Distributed I/O (PROFINET, PROFIBUS, or AS-i)
Table 9- 96
DPNRM_DG instruction error codes
Error code
Description
Restriction
0000
No error
-
7000
First call with REQ=0: No data transfer active; BUSY has the value 0.
-
7001
First call with REQ =1: No data transfer active; BUSY has the value 1.
Distributed I/Os
7002
Interim call (REQ irrelevant): Data transfer already active; BUSY has the
value 1.
Distributed I/Os
8090
Specified logical base address invalid: There is no base address.
-
8092
The RECORD parameter supports the following data types: Byte, Char,
Word, DWord, Int, UInt, USInt, SInt, DInt, UDInt, and arrays of these types.
8093
•
This instruction is not permitted for the module specified by LADDR
(S7-DP modules for S7-1200 are permitted).
•
LADDR specifies the I/O device instead of specifying the station. Select
the station (and not the image of the device) in the "Network" view of
the "Device configuration" to determine the diagnostic address for
LADDR.
•
DP protocol error at layer 2 (for example, slave failure or bus problems) Distributed I/Os
•
For ET200S, data record cannot be read in DPV0 mode.
80A2
-
80A3
DP protocol error with user interface/user
Distributed I/Os
80A4
Communication problem on the communication bus
The error occurs between the
CPU and the external DP
interface module.
80B0
•
The instruction is not possible for module type.
•
The module does not recognize the data record.
•
Data record number 241 is not permitted.
-
80B1
The length specified in the RECORD parameter is incorrect.
Specified length > record
length
80B2
The configured slot is not occupied.
-
80B3
Actual module type does not match the required module type.
-
80C0
There is no diagnostic information.
-
80C1
The data of the previous write job for the same data record on the module
have not yet been processed by the module.
-
80C2
The module is currently processing the maximum possible number of jobs
for a CPU.
-
80C3
The required resources (memory, etc.) are currently occupied.
-
80C4
Internal temporary error. The job could not be processed.
Repeat the job. If this error occurs frequently, check your system for electrical disturbance sources.
-
80C5
Distributed I/Os not available
Distributed I/Os
80C6
Data record transfer was stopped due to a priority class abort (restart or
background)
Distributed I/Os
8xyy1
General error codes
Refer to "Extended instructions, Distributed I/O: Error information for RDREC, WRREC, and
RALRM" (Page 403) for more information on general error codes.
S7-1200 Programmable controller
418
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.4 PROFIenergy
9.4
PROFIenergy
PROFIenergy is a manufacturer- and device-neutral profile for energy management with
PROFINET. To reduce electricity consumption during breaks in production and unplanned
interruptions, it is possible to shut down equipment in a coordinated and centralized manner
using PROFIenergy.
The PROFINET IO controller switches off the PROFINET devices/power modules using
special commands in the user program. You require no additional hardware. The PROFINET
devices interpret the PROFIenergy commands directly.
The S7-1200 CPU does not support the PE controller functionality. The S7-1200 CPU can
only act as a PROFIenergy entity (with I-device functionality).
PROFIenergy controller (PE controller)
The PE controller is a higher-level CPU (for example, an S7-1500) that activates or
deactivates the idle state of lower-level devices. The PE controller deactivates and
reactivates specific production components or complete production lines using the user
program. Lower-level devices receive commands from the user program through
corresponding instructions (function blocks).
The user program sends the commands using the PROFINET communication protocol. The
PE command can be either a control command to switch a PE entity to the energy-saving
mode, or a command to read a status or measured value.
You use the PE_I_DEV instruction to request data from a module. The user program has to
determine what information is being requested by the PE controller and retrieve it from the
energy module using data records. The module itself does not directly support the PE
commands. The module stores the energy measurement information in a shared area, and
the lower-level CPU (for example, an S7-1200) triggers the PE_I_DEV instruction to return it
to the PE controller.
PROFIenergy entity (PE entity)
The PE entity (for example, an S7-1200) receives the PROFIenergy commands of the PE
controller (for example, an S7-1200) and executes these accordingly (for example, by
returning a measured value or activating an energy saving mode). Implementation of the PE
entity in a PROFIenergy-capable device is device- and manufacturer-specific.
Reference information
You can find further information on PROFIenergy in the TIA Portal STEP 7 online help. You
can find examples that use the PROFIenergy instructions in the Industry Online Support in
the entry "PROFIenergy - Saving Energy with SIMATIC S7
(http://support.automation.siemens.com/WW/view/en/41986454)".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
419
Extended instructions
9.5 Interrupts
9.5
Interrupts
9.5.1
ATTACH and DETACH (Attach/detach an OB and an interrupt event)
instructions
You can activate and deactivate interrupt event-driven subprograms with the ATTACH and
DETACH instructions.
Table 9- 97
ATTACH and DETACH instructions
LAD / FBD
Table 9- 98
SCL
ret_val := ATTACH(
ob_nr:=_int_in_,
event:=_event_att_in_,
add:=_bool_in_);
Description
ret_val := DETACH(
ob_nr:=_int_in_,
event:=_event_att_ in);
DETACH disables interrupt OB subprogram
execution for a hardware interrupt event.
ATTACH enables interrupt OB subprogram
execution for a hardware interrupt event.
Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_ATT
Organization block identifier: Select from the available hardware
interrupt OBs that were created using the "Add new block" feature.
Double-click on the parameter field, then click on the helper icon to
see the available OBs.
EVENT
IN
EVENT_ATT
Event identifier: Select from the available hardware interrupt events
that were enabled in PLC device configuration for digital inputs or
high-speed counters. Double-click on the parameter field, then click
on the helper icon to see the available events.
ADD
(ATTACH only)
IN
Bool
•
ADD = 0 (default): This event replaces all previous event attachments for this OB.
•
ADD = 1: This event is added to previous event attachments for
this OB.
RET_VAL
OUT
Int
Execution condition code
S7-1200 Programmable controller
420
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
Hardware interrupt events
The following hardware interrupt events are supported by the CPU:
● Rising edge events: first 12 built-in CPU digital inputs (DIa.0 to DIb.3) and all SB digital
inputs
– A rising edge occurs when the digital input transitions from OFF to ON as a response
to a change in the signal from a field device connected to the input.
● Falling edge events: first 12 built-in CPU digital inputs (DIa.0 to DIb.3) and all SB digital
inputs
– A falling edge occurs when the digital input transitions from ON to OFF.
● High-speed counter (HSC) current value = reference value (CV = RV) events (HSC 1
through 6)
– A CV = RV interrupt for a HSC is generated when the current count transitions from an
adjacent value to the value that exactly matches a reference value that was previously
established.
● HSC direction changed events (HSC 1 through 6)
– A direction changed event occurs when the HSC is detected to change from
increasing to decreasing, or from decreasing to increasing.
● HSC external reset events (HSC 1 through 6)
– Certain HSC modes allow the assignment of a digital input as an external reset that is
used to reset the HSC count value to zero. An external reset event occurs for such a
HSC, when this input transitions from OFF to ON.
Enabling hardware interrupt events in the device configuration
Hardware interrupts must be enabled during the device configuration. You must check the
enable-event box in the device configuration for a digital input channel or a HSC, if you want
to attach this event during configuration or run time.
Check box options within the PLC device configuration:
● Digital input
– Enable rising edge detection
– Enable falling edge detection
● High-speed counter (HSC)
– Enable this high-speed counter for use
– Generate interrupt for counter value equals reference value count
– Generate interrupt for external reset event
– Generate interrupt for direction change event
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
421
Extended instructions
9.5 Interrupts
Adding new hardware interrupt OB code blocks to your program
By default, no OB is attached to an event when the event is first enabled. This is indicated by
the "HW interrupt:" device configuration "" label. Only hardware-interrupt
OBs can be attached to a hardware interrupt event. All existing hardware-interrupt OBs
appear in the "HW interrupt:" drop-down list. If no OB is listed, then you must create an OB
of type "Hardware interrupt" as follows. Under the project tree "Program blocks" branch:
1. Double-click "Add new block", select "Organization block (OB)" and choose "Hardware
interrupt".
2. Optionally, you can rename the OB, select the programming language (LAD, FBD or
SCL), and select the block number (switch to manual and choose a different block
number than that suggested).
3. Edit the OB and add the programmed reaction that you want to execute when the event
occurs. You can call FCs and FBs from this OB, to a nesting depth of six.
OB_NR parameter
All existing hardware-interrupt OB names appear in the device configuration "HW interrupt:"
drop-down list and in the ATTACH / DETACH parameter OB_NR drop-list.
EVENT parameter
When a hardware interrupt event is enabled, a unique default event name is assigned to this
particular event. You can change this event name by editing the "Event name:" edit box, but
it must be a unique name. These event names become tag names in the "Constants" tag
table, and appear on the EVENT parameter drop-down list for the ATTACH and DETACH
instruction boxes. The value of the tag is an internal number used to identify the event.
General operation
Each hardware event can be attached to a hardware-interrupt OB which will be queued for
execution when the hardware interrupt event occurs. The OB-event attachment can occur at
configuration time or at run time.
You have the option to attach or detach an OB to an enabled event at configuration time. To
attach an OB to an event at configuration time, you must use the "HW interrupt:" drop-down
list (click on the down arrow on the right) and select an OB from the list of available
hardware-interrupt OBs. Select the appropriate OB name from this list, or select "" to remove the attachment.
You can also attach or detach an enabled hardware interrupt event during run time. Use the
ATTACH or DETACH program instructions during run time (multiple times if you wish) to
attach or detach an enabled interrupt event to the appropriate OB. If no OB is currently
attached (either from a "" selection in device configuration, or as a result of
executing a DETACH instruction), the enabled hardware interrupt event is ignored.
S7-1200 Programmable controller
422
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
DETACH operation
Use the DETACH instruction to detach either a particular event or all events from a particular
OB. If an EVENT is specified, then only this one event is detached from the specified
OB_NR; any other events currently attached to this OB_NR will remain attached. If no
EVENT is specified, then all events currently attached to OB_NR will be detached.
Condition codes
Table 9- 99
Condition codes
RET_VAL (W#16#....)
ENO
Description
0000
1
No error
0001
1
Nothing to Detach (DETACH only)
8090
0
OB does not exist
8091
0
OB is wrong type
8093
0
Event does not exist
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
423
Extended instructions
9.5 Interrupts
9.5.2
Cyclic interrupts
9.5.2.1
SET_CINT (Set cyclic interrupt parameters)
Table 9- 100 SET_CINT (Set cyclic interrupt parameters)
LAD / FBD
SCL
ret_val := SET_CINT(
ob_nr:=_int_in_,
cycle:=_udint_in_,
phase:=_udint_in_);
Description
Set the specified interrupt OB to begin cyclic execution
that interrupts the program scan.
Table 9- 101 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_CYCLIC
OB number (accepts symbolic name)
CYCLE
IN
UDInt
Time interval, in microseconds
PHASE
IN
UDInt
Phase shift, in microseconds
RET_VAL
OUT
Int
Execution condition code
Examples: time parameter
● If the CYCLE time = 100 us, then the interrupt OB referenced by OB_NR interrupts the
cyclic program scan every 100 us. The interrupt OB executes and then returns execution
control to the program scan, at the point of interruption.
● If the CYCLE time = 0, then the interrupt event is deactivated and the interrupt OB is not
executed.
● The PHASE (phase shift) time is a specified delay time that occurs before the CYCLE
time interval begins. You can use the phase shift to control the execution timing of lower
priority OBs.
S7-1200 Programmable controller
424
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
If lower and higher priority OBs are called in the same time interval, the lower priority OB is
only called after the higher priority OB has finished processing. The execution start time for
the low priority OB can shift depending on the processing time of higher priority OBs.
If you want to start the execution of a lower priority OB on a fixed time cycle, then phase shift
time should be greater then the processing time of higher priority OBs.
Table 9- 102 Condition codes
RET_VAL (W#16#....)
Description
0000
No error
8090
OB does not exist or is of wrong type
8091
Invalid cycle time
8092
Invalid phase shift time
80B2
OB has no attached event
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
425
Extended instructions
9.5 Interrupts
9.5.2.2
QRY_CINT (Query cyclic interrupt parameters)
Table 9- 103 QRY_CINT (Query cyclic interrupt)
LAD / FBD
SCL
ret_val := QRY_CINT(
ob_nr:=_int_in_,
cycle=>_udint_out_,
phase=>_udint_out__,
status=>_word_out_);
Description
Get parameter and execution status from a cyclic
interrupt OB. The values that are returned existed
at the time QRY_CINT was executed.
Table 9- 104 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_CYCLIC
OB number (accepts symbolic name like OB_MyOBName)
RET_VAL
OUT
Int
Execution condition code
CYCLE
OUT
UDInt
Time interval, in microseconds
PHASE
OUT
UDInt
Phase shift, in microseconds
STATUS
OUT
Word
Cyclic interrupt status code:
•
Bits 0 to 4, see the STATUS table below
•
Other bits, always 0
Table 9- 105 STATUS parameter
Bit
Value
Description
0
0
During CPU RUN
1
During startup
0
The interrupt is enabled.
1
Interrupt is disabled via the DIS_IRT instruction.
0
The interrupt is not active or has elapsed.
1
The interrupt is active.
1
2
4
0
The OB identified by OB_NR does not exist.
1
The OB identified by OB_NR exists.
Other Bits
Always 0
S7-1200 Programmable controller
426
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
If an error occurs, RET_VAL displays the appropriate error code and the parameter STATUS
= 0.
Table 9- 106 RET_VAL parameter
9.5.3
RET_VAL (W#16#....)
Description
0000
No error
8090
OB does not exist or is of wrong type.
80B2
OB has no attached event.
Time of day interrupts
WARNING
If an attacker can access your networks through Network Time Protocol (NTP)
synchronization, the attacker can possibly take limited control of your process by shifting
the CPU system time.
The NTP client feature of the S7-1200 CPU is disabled by default, and, when enabled, only
allows configured IP addresses to act as an NTP server. The CPU disables this feature by
default, and you must configure this feature to allow remotely-controlled CPU system time
corrections.
The S7-1200 CPU supports "time of day" interrupts and clock instructions that depend upon
accurate CPU system time. If you configure NTP and accept time synchronization from a
server, you must ensure that the server is a trusted source. Failure to do so can cause a
security breach that allows an unknown user to take limited control of your process by
shifting the CPU system time.
For security information and recommendations, please see our "Operational Guidelines for
Industrial Security" (http://www.industry.siemens.com/topics/global/en/industrialsecurity/Documents/operational_guidelines_industrial_security_en.pdf) on the Siemens
Service and Support site.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
427
Extended instructions
9.5 Interrupts
9.5.3.1
SET_TINTL (Set time of day interrupt)
Table 9- 107 SET_TINTL (Set date and time of day interrupt with DTL data type)
LAD / FBD
SCL
ret_val := SET_TINTL(
OB_NR:=_int_in_,
SDT:=_dtl_in_,
LOCAL:=_bool_in_
PERIOD:=_word_in_
ACTIVATE:=_bool_in_);
Description
Set a date and time of day interrupt. The
program interrupt OB can be set for one
execution, or for recurring execution with
an assigned time period.
Table 9- 108 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_TOD (INT)
OB number (accepts symbolic name)
SDT
IN
DTL
Start date and time: Seconds and milliseconds are ignored and can be
set to 0.
LOCAL
IN
Bool
0 = Use system time
1 = Use local time (if the CPU is configured for local time, otherwise
use system time)
PERIOD
IN
Word
The period from the starting date and time for recurring interrupt event.
•
W#16#0000 = Once
•
W#16#0201 = Every minute
•
W#16#0401 = Every hour
•
W#16#1001 = Daily
•
W#16#1201 = Weekly
•
W#16#1401 = Monthly
•
W#16#1801 = yearly
•
W#16#2001 = End of month
ACTIVATE
IN
Bool
0 = ACT_TINT must be executed to activate the interrupt event.
1 = The interrupt event is activated.
RET_VAL
OUT
Int
Execution condition code
Your program can use SET_TINTL to set a date and time of day interrupt event that will
execute the assigned interrupt OB. The start date and time is set by parameter SDT and the
time period for recurring interrupts (for example, daily or weekly) is set by parameter
PERIOD. If you set the repetition period to monthly, then you must set the start date to a day
from 1 to 28. The days 29 to 31 may not be used because they do not occur in February. If
you want an interrupt event at the end of each month, then use end of month for parameter
PERIOD.
S7-1200 Programmable controller
428
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
The DTL data weekday value in parameter SDT is ignored. Set a CPU's current date and
time using the "Set time of day" function in the "Online & diagnostics" view of an online CPU.
You must set the month, day of month, and year. STEP 7 calculates the interrupt period
based on the CPU date and time clock.
Note
The first hour of the day does not exist when changing from summer to winter (daylight
saving time). Use a start time within the second hour or use an additional time delay interrupt
within the first hour.
Table 9- 109 Condition code
9.5.3.2
RET_VAL (W#16#....)
Description
0000
No error
8090
Invalid OB_NR parameter
8091
Invalid SDT start time parameter:
(for example, a start time within the skipped hour at the start of
daylight savings time)
8092
Invalid PERIOD parameter
80A1
The start time is in the past.
(This error code only occurs with PERIOD = W #16#0000.)
CAN_TINT (Cancel time of day interrupt)
Table 9- 110 CAN_TINT (Cancel date and time of day interrupt)
LAD / FBD
SCL
ret_val:=CAN_TINT(_int_in);
Description
Cancels the start date and time
of day interrupt event for the
specified interrupt OB.
Table 9- 111 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_TOD (INT)
OB number (accepts symbolic name)
RET_VAL
OUT
Int
Execution condition code
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
429
Extended instructions
9.5 Interrupts
Table 9- 112 Condition codes
9.5.3.3
RET_VAL (W#16#....)
Description
0000
No error
8090
Invalid OB_NR parameter
80A0
No start date / time set for that interrupt OB
ACT_TINT (Activate time of day interrupt)
Table 9- 113 ACT_TINT (Activate date and time of day interrupt)
LAD / FBD
SCL
ret_val:=ACT_TINT(_int_in_);
Description
Activates the start date and
time of day interrupt event for
the specified interrupt OB.
Table 9- 114 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_TOD (INT)
OB number (accepts symbolic name)
RET_VAL
OUT
Int
Execution condition code
Table 9- 115 Condition codes
RET_VAL (W#16#....)
Description
0000
No error
8090
Invalid OB_NR parameter
80A0
Start date and time-of day not set, for the relevant time-of-day
interrupt OB
80A1
The activated time is in the past. The error only occurs when the
interrupt OB is set to execute once only.
S7-1200 Programmable controller
430
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
9.5.3.4
QRY_TINT (Query status of time of day interrupt)
Table 9- 116 QRY_TINT (Query date and time of day interrupt)
LAD / FBD
SCL
ret_val:=QRY_TINT(
OB_NR:=_int_in_,
STATUS=>_word_out_);
Description
Queries the date and time of day interrupt status for
the specified interrupt OB.
Table 9- 117 Data types for the parameters
Parameter and type
Data type
Description
OB_NR
IN
OB_TOD (INT)
OB number (accepts symbolic name) of the interrupt OB to query
RET_VAL
OUT
Int
Execution condition code
STATUS
OUT
Word
Status of the specified interrupt OB
Table 9- 118 STATUS parameter
Bit
Value
0
Description
0
In Run
1
In Startup
0
The interrupt is enabled.
1
The interrupt is disabled.
2
0
The interrupt is not active or has expired.
1
The interrupt is active.
4
0
The assigned OB_NR does not exist.
1
An OB with the assigned OB_NR exists.
1
The date and time of day interrupt uses local time.
0
The date and time of day interrupt uses system time.
1
6
Others
Always 0
Table 9- 119 Condition code
RET_VAL (W#16#....)
Description
0000
No error
8090
Invalid OB_NR parameter
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
431
Extended instructions
9.5 Interrupts
9.5.4
Time delay interrupts
You can start and cancel time delay interrupt processing with the SRT_DINT and CAN_DINT
instructions, or query the interrupt status with the QRY_DINT instruction. Each time delay
interrupt is a one-time event that occurs after the specified delay time. If the time delay event
is cancelled before the time delay expires, the program interrupt does not occur.
Table 9- 120 SRT_DINT, CAN_DINT, and QRY_DINT instructions
LAD / FBD
SCL
ret_val := SRT_DINT(
ob_nr:=_int_in_,
dtime:=_time_in_,
sign:=_word_in_);
Description
ret_val := CAN_DINT(
ob_nr:=_int_in_);
CAN_DINT cancels a time delay interrupt that has
already started. The time delay interrupt OB is not
executed in this case.
ret_val := QRY_DINT(
ob_nr:=_int_in_,
status=>_word_out_);
QRY_DINT queries the status of the time delay
interrupt specified by the OB_NR parameter.
SRT_DINT starts a time delay interrupt that executes an OB when the delay time specified by
parameter DTIME has elapsed.
Table 9- 121 Data types for the parameters
1
Parameter and type
Data type
Description
OB_NR
OB_DELAY
Organization block (OB) to be started after a time-delay: Select from
the available time-delay interrupt OBs that were created using the "Add
new block" project tree feature. Double-click on the parameter field,
then click on the helper icon to see the available OBs.
IN
DTIME 1
IN
Time
Time delay value (1 to 60000 ms)
SIGN 1
IN
Word
Not used by the S7-1200: Any value is accepted. A value must be assigned to prevent errors.
RET_VAL
OUT
Int
Execution condition code
STATUS
OUT
Word
QRY_DINT instruction: Status of the specified time-delay interrupt OB,
see the table below
Only for SRT_DINT
S7-1200 Programmable controller
432
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
Operation
When EN=1, the SRT_DINT instruction starts the internal time delay timer (DTIME). When
the time delay elapses, the CPU generates a program interrupt that triggers the execution of
the associated time delay interrupt OB. You can cancel an in-process time delay interrupt
before the specified time delay occurs by executing the CAN_DINT instruction. The total
number of active time delay interrupt events must not exceed four.
Note
The SRT_DINT starts the time delay timer on every scan when EN=1. Assert EN=1 as a
one-shot rather than just setting EN=1 to begin your time delay.
Timing diagram for the SRT_DINT instruction:
①
Time delay interrupt executes
Adding time delay interrupt OBs to your project
You can only assign time delay interrupt OBs to the SRT_DINT and CAN_DINT instructions.
No time delay interrupt OB exists in a new project. You must add time delay interrupt OBs to
your project. To create a time-delay interrupt OB, follow these steps:
1. Double-click the "Add new block" item in the "Program blocks" branch of the project tree,
select "Organization block (OB)", and choose "Time delay interrupt".
2. You have the option to rename the OB, select the programming language, or select the
block number. Switch to manual numbering if you want to assign a different block number
than the number that was assigned automatically.
3. Edit the time delay interrupt OB subprogram and create programmed reaction that you
want to execute when the time delay timeout event occurs. You can call other FC and FB
code blocks from the time delay interrupt OB, with a maximum nesting depth of six.
4. The newly assigned time delay interrupt OB names will be available when you edit the
OB_NR parameter of the SRT_DINT and CAN_DINT instructions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
433
Extended instructions
9.5 Interrupts
QRY_DINT parameter STATUS
Table 9- 122 If there is an error (REL_VAL <> 0), then STATUS = 0.
Bit
Value
Description
0
0
In RUN
1
In startup
0
The interrupt is enabled.
1
The interrupt is disabled.
0
The interrupt is not active or has elapsed.
1
The interrupt is active.
0
An OB with an OB number given in OB_NR does not exist.
1
An OB with an OB number given in OB_NR exists.
1
2
4
Other bits
Always 0
Condition codes
Table 9- 123 Condition codes for SRT_DINT, CAN_DINT, and QRY_DINT
RET_VAL (W#16#...)
Description
0000
No error occurred
8090
Incorrect parameter OB_NR
8091
Incorrect parameter DTIME
80A0
Time delay interrupt has not started.
S7-1200 Programmable controller
434
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.5 Interrupts
9.5.5
DIS_AIRT and EN_AIRT (Delay/enable execution of higher priority interrupts
and asynchronous error events) instructions
Use the DIS_AIRT and EN_AIRT instructions to disable and enable alarm interrupt
processing.
Table 9- 124 DIS_AIRT and EN_AIRT instructions
LAD / FBD
SCL
DIS_AIRT();
EN_AIRT();
Description
DIS_AIRT delays the processing of new interrupt events. You can execute
DIS_AIRT more than once in an OB.
EN_AIRT enables the processing of interrupt events that you previously disabled
with the DIS_AIRT instruction. Each DIS_AIRT execution must be cancelled by an
EN_AIRT execution.
The EN_AIRT executions must occur within the same OB, or any FC or FB called
from the same OB, before interrupts are enabled again for this OB.
Table 9- 125 Data types for the parameters
Parameter and type
RET_VAL
OUT
Data type
Description
Int
Number of delays = number of DIS_AIRT executions in the queue.
The DIS_AIRT executions are counted by the operating system. Each of these remains in
effect until it is cancelled again specifically by an EN_AIRT instruction, or until the current OB
has been completely processed. For example: if you disabled interrupts five times with five
DIS_AIRT executions, you must cancel these with five EN_AIRT executions before interrupts
become enabled again.
After the interrupt events are enabled again, the interrupts that occurred while DIS_AIRT was
in effect are processed, or the interrupts are processed as soon as the current OB has been
executed.
Parameter RET_VAL indicates the number of times that interrupt processing was disabled,
which is the number of queued DIS_AIRT executions. Interrupt processing is only enabled
again when parameter RET_VAL = 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
435
Extended instructions
9.6 Alarms
9.6
Alarms
9.6.1
Gen_UsrMsg (Generate user diagnostic alarms)
Table 9- 126 Gen_UsrMsg instruction
LAD / FBD
SCL
ret_val :=Gen_UsrMsg(
Mode:=_uint_in_,
TextID:=_uint_in_,
TextListID:=_uint_in_,
AssocValues:=_struct_inout_);
Description
You use the "Gen_UsrMsg" instruction to
generate a user diagnostic alarm that can be
either an incoming or outgoing alarm. By
means of user diagnostic alarms, you can
write a user entry to the diagnostics buffer and
send a corresponding alarm.
The entry in the diagnostic buffer is created
synchronously. Alarm transmission is asynchronous.
If an error occurs during the execution of an
instruction, it is output via the parameter
RET_VAL.
Content of the alarm
A text list defines the content of the alarm:
● Define the text list you want to use with the parameter TextListID. For this purpose open
the dialog "Text lists" in the project navigation. Show the column "ID" in the dialog "Text
lists". Apply the ID at the parameter TextListID.
● Use the parameter TextID to select the text list entry you want to write in the diagnostic
buffer. For this purpose select an entry from the "Text lists entries" dialog by applying a
number from the columns "Range from / range to" at the parameter TextID. You must use
the same number from both the "Range from" and "Range to" columns for the text list
entry.
Refer to the STEP 7 Information System for detailed information about text lists.
Defining associated values
The text list entry defines new associated values to be added to the alarm:
● Add the following information to the text list entry to define associated values:
@@
● Use the system data type AssocValues to specify which associated value to add when
generating the alarm.
Refer to the STEP 7 Information System for detailed information about the structure of
associated values.
S7-1200 Programmable controller
436
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.6 Alarms
Parameters
The following table shows the parameters of the "Gen_UsrMsg" instruction:
Parameter
Declaration
Data type
Memory area
Description
Mode
Input
UInt
I, Q, M, D, L or
constant
Parameters for selecting the
status of the alarm:
•
1: incoming alarm
•
2: outgoing alarm
TextID
Input
UInt
I, Q, M, D, L or
constant
ID of the text list entry that
should be used for the alarm
text.
TextListID
Input
UInt
I, Q, M, D, L or
constant
ID of the text list that contains text list entry.
Ret_Val
Return
Int
I, Q, M, D, L
Error code of the instruction.
AssocValues
InOut
VARIANT
D, L
Pointer to the system data
type AssocValues that allows you to define the associated values.
For additional information on valid data types, refer to "Data types (Page 125)".
Parameter AssocValues
Use the system data type AssocValues to define which associated values will be sent. A
maximum of eight associated values are possible. Enter the data type "AssocValues" as a
data block to create the structure.
You select associated values by entering the numbers of the associated values for the
parameters Value[x]. Note the following:
● The Gen_UsrMsg instruction treats the values for TextID and TextListID as associated
values to be sent. As a result, "1" and "2" are pre-assigned as numbers for addressing
associated values. Do not use the numbers "1" or "2" to address associated values.
● Address the associated value at parameter Value [1] as number "3", at parameter Value
[2] as number "4", and so forth.
Byte
Parameter
Data type
Start value
Description
Number of
the associated value
0..1
Value[1]
UINT
0
First associated 3
value of the
alarm.
2..3
Value[2]
UINT
0
Second associated value of
the alarm.
4
4..5
Value[3]
UINT
0
...
5
6..7
Value[4]
UINT
0
...
6
8..9
Value[5]
UINT
0
...
7
10..11
Value[6]
UINT
0
...
8
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
437
Extended instructions
9.6 Alarms
Byte
Parameter
Data type
Start value
Description
Number of
the associated value
12..13
Value[7]
UINT
0
...
9
14..15
Value[8]
UINT
0
Eighth associated value of
the alarm.
10
Parameter RET_VAL
The following table defines output values for the RET_VAL parameter. See also Common
error codes for the Extended instructions (Page 553).
Error code*
(W#16#...)
Explanation
0000
No error
8080
Value in the MODE parameter is not supported.
80C1
Resource bottleneck due to too many parallel calls.
8528
Parameter 5 (AssocValues) is not byte-aligned.
853A
Parameter 5 (AssocValues) references an invalid point.
* You can display the error code as either integer or hexadecimal in the program editor.
S7-1200 Programmable controller
438
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7
Diagnostics (PROFINET or PROFIBUS)
9.7.1
Diagnostic instructions
The following diagnostic instructions can be used with either PROFINET or PROFIBUS:
● RD_SINFO instruction (Page 440): Reads the current OB's start information
● LED instruction (Page 450): Reads the state of the LEDs for a distributed I/O device.
● Get_IM_Data instruction (Page 451): Checks the identification and maintenance (I&M)
data for a specified module or sub-module.
● Get_Name instruction (Page 453): Reads the name of a PROFINET IO device,
PROFIBUS slave, or AS-i slave.
● GetStationInfo instruction (Page 460): Reads the IP or MAC address of a PROFINET IO
device in the local IO system or a PROFINET IO device located in a lower-level IO
system (connected using CP/CM modules).
● DeviceStates instruction (Page 468): Retrieves the operational states for a distributed I/O
device within an I/O subsystem.
● ModuleStates instruction (Page 474): Retrieves the operational states for the modules in
a distributed I/O device.
● GET_DIAG instruction (Page 480): Reads the diagnostic information from a specified
device.
Note
You can only use the GetStationInfo instruction with PROFINET IO devices. You cannot use
the instruction with PROFIBUS DP slaves.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
439
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.2
RD_SINFO (Read current OB start information)
Description
Table 9- 127 RD_SINFO instruction
LAD / FBD
SCL
Description
ret_val := RD_SINFO(
You use the instruction "RD_SINFO" to read the
TOP_SI=>_variant_out_, start information of the following OBs:
START_UP_SI=>_variant_out_)
;
•
Last OB called that has not yet been completely executed
• Last startup OB that the CPU started
There is no time stamp in either case. If the call is
in OB 100, OB 101 or OB 102, two identical start
information messages will be returned.
Parameter
The following table shows the parameters of the "RD_SINFO" instruction:
Parameter
Declaration
Data type
Memory area
Description
RET_VAL
Return
INT
I, Q, M, D, L
Error information
TOP_SI
Output
VARIANT
D, L
Start information of the current OB
START_UP_SI
Output
VARIANT
D, L
Start information of the startup OB last
started
You will find more detailed information on valid data types in "Data types (Page 125)".
SDTs of the TOP_SI parameter
The following table shows the possible SDTs for the TOP_SI parameter:
Organization blocks (OB)
System data types (SDT)
System data type numbers
Any
SI_classic*
592*
SI_none
593
ProgramCycleOB
SI_ProgramCycle
594
TimeOfDayOB
SI_TimeOfDay
595
TimeDelayOB
SI_Delay
596
CyclicOB
SI_Cyclic
597
ProcessEventOB
SI_HWInterrupt
598
ProfileEventOB
SI_Submodule
601
SynchronousCycleOB
SI_SynchCycle
602
IOredundancyErrorOB
SI_IORedundancyError
604
CPUredundancyErrorOB
SI_CPURedundancyError
605
StatusEventOB
UpdateEventOB
S7-1200 Programmable controller
440
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Organization blocks (OB)
System data types (SDT)
System data type numbers
TimeErrorOB
SI_TimeError
606
DiagnosticErrorOB
SI_DiagnosticInterrupt
607
PullPlugEventOB
SI_PlugPullModule
608
PeripheralAccessErrorOB
SI_AccessError
609
RackStationFailureOB
SI_StationFailure
610
ServoOB
SI_Servo
611
IpoOB
SI_Ipo
612
StartupOB
SI_Startup
613
ProgrammingErrorOB
SI_ProgIOAccessError
614
IOaccessErrorOB
*The SI_classic SDT is not applicable for the S7-1200. The S7-1200 CPU returns a RET_VAL of #16#8081 if the TOP_SI
parameter is of type SI_classic.
SDTs of the START_UP_SI parameter
The following table shows the possible SDTs for the START_UP_SI parameter:
System data types (SDT)
System data type numbers
SI_classic*
592
SI_none
593
SI_Startup
613
*The SI_classic SDT is not applicable for the S7-1200. The S7-1200 CPU returns a RET_VAL of
#16#8083 if the START_UP_SI parameter is of type SI_classic.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
441
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Structures
The following tables define the structure elements of the individual structures:
Table 9- 128 SI_classic structure
Structure element
Data type
Description
EV_CLASS
BYTE
•
Bits 0 to 3: Event ID
•
Bits 4 to 7: Event class
EV_NUM
BYTE
Event number
PRIORITY
BYTE
Priority class number
(Meaning of B#16#FE: OB not available or disabled or cannot be started in
current operating mode)
NUM
BYTE
OB number
TYP2_3
BYTE
Data ID 2_3:
TYP1
BYTE
ZI1
WORD
Additional information 1
ZI2_3
DWORD
Additional information 2_3
Identifies the information entered in ZI2_3
Data ID 1:
Identifies the information entered in ZI1
Table 9- 129 SI_none structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Table 9- 130 SI_ProgramCycle structure
Structure element
Data type
SI_Format
USINT
Description
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 1
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Initial_Call
BOOL
For OB_Class = 1, 30, 52, 61, 65
Remanence
BOOL
For OB_Class = 1
S7-1200 Programmable controller
442
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 131 SI_TimeOfDay structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 10
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
CaughtUp
BOOL
For OB_Class = 10
SecondTime
BOOL
For OB_Class = 10
Table 9- 132 SI_Delay structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 20
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Sign
WORD
For OB_Class = 20
Table 9- 133 SI_Cyclic structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 30
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Initial_Call
BOOL
For OB_Class = 1, 30, 52, 61, 65
Event_Count
INT
For OB_Class = 30, 51, 52, 61, 65, 91, 92
Table 9- 134 SI_HWInterrupt structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 40
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_IO
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
USI
WORD
For OB_Class = 40
IChannel
USINT
For OB_Class = 40
EventType
BYTE
For OB_Class = 40
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
443
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 135 SI_Submodule structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_IO
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Slot
UINT
For OB_Class = 55, 56, 57
Specifier
WORD
For OB_Class = 55, 56, 57
Table 9- 136 SI_SynchCycle structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 61
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Initial_Call
BOOL
For OB_Class = 1, 30, 52, 61, 65
PIP_Input
BOOL
For OB_Class = 61, 91, 92
PIP_Output
BOOL
For OB_Class = 61, 91, 92
IO_System
USINT
For OB_Class = 61, 91, 92
Event_Count
INT
For OB_Class = 30, 51, 52, 61, 65, 91, 92
SyncCycleTime
LTIME
Calculated cycle time
Table 9- 137 SI_IORedundancyError structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 70
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_ANY
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Event_Class
BYTE
For OB_Class = 70, 83, 85, 86
Fault_ID
BYTE
For OB_Class = 70, 80, 83, 85, 86
S7-1200 Programmable controller
444
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 138 SI_CPURedundancyError structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 72
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Switch_Over
BOOL
For OB_Class = 72
Table 9- 139 SI_TimeError structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 80
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Fault_ID
BYTE
For OB_Class = 70, 80, 83, 85, 86
Csg_OBnr
OB_ANY
For OB_Class = 80
Csg_Prio
UINT
For OB_Class = 80
Table 9- 140 SI_DiagnosticInterrupt structure
Structure element
Data type
SI_Format
USINT
Description
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 82
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
IO_State
WORD
For OB_Class = 82
LADDR
HW_ANY
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Channel
UINT
For OB_Class = 82
MultiError
BOOL
For OB_Class = 82
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
445
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 141 SI_PlugPullModule structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 83
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_IO
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Event_Class
BYTE
For OB_Class = 70, 83, 85, 86
Fault_ID
BYTE
For OB_Class = 70, 80, 83, 85, 86
Table 9- 142 SI_AccessError structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 85
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_IO
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Event_Class
BYTE
For OB_Class = 70, 83, 85, 86
Fault_ID
BYTE
For OB_Class = 70, 80, 83, 85, 86
IO_Addr
UINT
For OB_Class = 85
IO_LEN
UINT
For OB_Class = 85
Table 9- 143 SI_StationFailure structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 86
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LADDR
HW_IO
For OB_Class = 40, 51, 55, 56, 57, 70, 82, 83, 85, 86, 91, 92
Event_Class
BYTE
For OB_Class = 70, 83, 85, 86
Fault_ID
BYTE
For OB_Class = 70, 80, 83, 85, 86
S7-1200 Programmable controller
446
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 144 SI_Servo structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 91
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Initial_Call
BOOL
For OB_Class = 1, 30, 52, 61, 65
PIP_Input
BOOL
For OB_Class = 61, 91, 92
PIP_Output
BOOL
For OB_Class = 61, 91, 92
IO_System
USINT
For OB_Class = 61, 91, 92
Event_Count
INT
For OB_Class = 30, 51, 52, 61, 65, 91, 92
Synchronous
BOOL
Table 9- 145 SI_Ipo structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 92
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
Initial_Call
BOOL
For OB_Class = 1, 30, 52, 61, 65
PIP_Input
BOOL
For OB_Class = 61, 91, 92
PIP_Output
BOOL
For OB_Class = 61, 91, 92
IO_System
USINT
For OB_Class = 61, 91, 92
Event_Count
INT
For OB_Class = 30, 51, 52, 61, 65, 91, 92
Reduction
UINT
For OB_Class = 92
Table 9- 146 SI_Startup structure
Structure element
Data type
SI_Format
USINT
Description
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT := 100
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
LostRetentive
BOOL
For OB_Class = 100
LostRTC
BOOL
For OB_Class = 100
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
447
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 147 SI_ProgIOAcessError structure
Structure element
Data type
Description
SI_Format
USINT
•
16#FF = No information
•
16#FE = Optimized start information
OB_Class
USINT
OB class for "No information" or "Optimized start information"
OB_Nr
UINT
OB number (1 ... 32767)
BlockNr
UINT
For OB_Class = 121, 122
Reaction
USINT
For OB_Class = 121, 122
Fault_ID
BYTE
For OB_Class = 121, 122
BlockType
USINT
For OB_Class = 121, 122
Area
USINT
For OB_Class = 121, 122
DBNr
DB_ANY
For OB_Class = 121, 122
Csg_OBNr
OB_ANY
For OB_Class = 121, 122
Csg_Prio
USINT
For OB_Class = 121, 122
Width
USINT
For OB_Class = 121, 122
Note
If this was created with the block property "Standard", the structure elements specified for
the SI_classic structure are identical in content to the temporary tags of an OB.
Note, however, that temporary tags of the individual OBs can have different names and
different data types. Also note that the call interface of each OB includes additional
information regarding the date and the time of the OB request.
Bits 4 to 7 of the EV_CLASS structure element contain the event class. The following values
are possible here:
● 1: Start events from standard OBs
● 2: Start events from synchronous error OBs
● 3: Start events from asynchronous error OBs
The PRIORITY structure element supplies the priority class belonging to the current OB.
Apart from these two elements, NUM is also relevant. NUM contains the number of the
current OB or the startup OB that was started last.
S7-1200 Programmable controller
448
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
RET_VAL parameter
The following table shows the meaning of the values of the RET_VAL parameter:
Error code*
(W#16#...)
Explanation
8081
Start information of the current OB does not correspond to the specified system data type
8083
Start information of the last startup OB started does not correspond to the specified system data type
* You can display the error code as either integer or hexadecimal values in the program editor.
Example
A time error interrupt OB (OB 80) is the OB that was called last and that has not yet been
completely processed. Startup OB (OB 100) is the startup OB that was started last. The
instruction call to read the startup information is as follows, where RD_SINFO_DB is the data
block that contains tags of the SDTs for types of OBs:
The following table shows the assignment between the structure elements of the TOP_SI
parameter of the "RD_SINFO" instruction and the associated local tags of OB 80.
TOP_SI
structure element
Data type
OB 80 - Associated local tag
Data type
EV_CLASS
BYTE
OB80_EV_CLASS
BYTE
EV_NUM
BYTE
OB80_FLT_ID
BYTE
PRIORITY
BYTE
OB80_PRIORITY
BYTE
NUM
BYTE
OB80_OB_NUMBR
BYTE
TYP2_3
BYTE
OB80_RESERVED_1
BYTE
TYP1
BYTE
OB80_RESERVED_2
BYTE
ZI1
WORD
OB80_ERROR_INFO
WORD
ZI2_3
DWORD
OB80_ERR_EV_CLASS
BYTE
OB80_ERR_EV_NUM
BYTE
OB80_OB_PRIORITY
BYTE
OB80_OB_NUM
BYTE
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
449
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
The following table shows the assignment between the structure elements of the
START_UP_SI parameter of the "RD_SINFO" instruction and the associated local tags of
OB 100.
START_UP_SI
structure element
Data type
OB 100 - Local tag
Data type
EV_CLASS
BYTE
OB100_EV_CLASS
BYTE
EV_NUM
BYTE
OB100_STRTUP
BYTE
PRIORITY
BYTE
OB100_PRIORITY
BYTE
NUM
BYTE
OB100_OB_NUMBR
BYTE
TYP2_3
BYTE
OB100_RESERVED_1
BYTE
TYP1
BYTE
OB100_RESERVED_2
BYTE
ZI1
WORD
OB100_STOP
WORD
ZI2_3
DWORD
OB100_STRT_INFO
DWORD
9.7.3
LED (Read LED status)
Table 9- 148 LED instruction
LAD / FBD
SCL
ret_val := LED(
laddr:=_word_in_,
LED:=_uint_in_);
Description
Use the LED instruction to read the state of the LEDs on a CPU or
interface. The specified LED state is returned by the RET_VAL output.
Table 9- 149 Data types for the parameters
Parameter and type
Data type
Description
LADDR
IN
HW_IO
Identification number of the CPU or interface1
LED
IN
UInt
LED identifier number
RET_VAL
1
OUT
Int
1
RUN/STOP
Color 1 = green, color 2 = yellow
2
Error
Color 1 = red
3
Maintenance
Color 1 = yellow
4
Redundancy
Not applicable
5
Link
Color 1 = green
6
Tx/Rx
Color 1 = yellow
Status of the LED
For example, you can select the CPU (such as "PLC_1") or the PROFINET interface from the drop-down list of the
parameter.
S7-1200 Programmable controller
450
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 150 Status of RET_VAL
RET_VAL (W#16#...)
Description
0 to 9 LED state
0
LED does not exist
1
Off
2
Color 1 On (solid)
3
Color 2 On (Solid)
4
Color 1 flashing at 2 Hz
5
Color 2 flashing 2 Hz
6
Color 1 & 2 flashing alternatively at 2 Hz
7
Color 1 on (Tx/Rx)
8
Color 2 on (Tx/Rx)
9
State of the LED is not available
8091
Device identified by LADDR does not exist
8092
Device identified by LADDR does not support LEDs
8093
LED identifier not defined
80Bx
CPU identified by LADDR does not support the LED instruction
9.7.4
Get_IM_Data (Read the identification and maintenance data)
You use the Get_IM_Data instruction to check the identification and maintenance (I&M) data
for the specified module or sub-module.
Table 9- 151 Get_IM_Data instruction
LAD / FBD
SCL
"GET_IM_DATA_DB"(LADDR:=16#0
,
IM_TYPE:=0,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_,
Description
Use the Get_IM_Data instruction to check the
identification and maintenance (I&M) data for
the specified module or sub-module.
DATA:=_variant_inout_);
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
451
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 152 Data types for the parameters
Parameter and type
Data type
Description
LADDR
Input
HW_IO
Identifier of the module
IM_TYPE
Input
UInt
Identification and maintenance (I&M) data number:
•
0: I&M0 (MLFB, serial number, version, and other information)
•
1: I&M1 (Designators)
•
2: I&M2 (Installation date)
•
3: I&M3 (Descriptor)
•
4: I&M4 (Signature)
RET_VAL
Output
Int
Status (condition code)
DATA
InOut
Variant
I&M data (STRING or an array of BYTE); recommend use of the SDT
"IM0_Data" for IM_TYPE = 0.
Identification and maintenance (I&M) data can help you to check the system configuration,
detect hardware changes, or view maintenance data. Module identification data (I data) is
read only. Module maintenance data (M data) depends on system information, such as the
installation date. M data are created during maintenance planning and written to the module:
● If the data type used at the parameter DATA is a string, then the current length of the
string is set according to the length of the I&M data.
● If the data type used at the parameter DATA is an array of Byte or Char, then the I&M
data are copied in as a sequence of bytes.
● If the data type used at the parameter DATA is a structure, then the I&M data are copied
in as a sequence of bytes.
● If the given array of byte/char at DATA is longer than the requested I&M data, then the
byte value 16#00 is appended.
● Other data types are not supported and error 8093 is returned.
Table 9- 153 Condition codes
RET_VAL (W#16#...)
Description
0
No error
8091
LADDR does not exist
8092
LADDR does not address a HW object which supports I&M data
8093
Data type given at parameter DATA is not supported
80B1
DATA instruction not supported by the CPU for this LADDR
80B2
IM_TYPE not supported by the CPU
8452
The complete I&M information does not fit into the variable given at the DATA parameter. A partial result up to the byte length of the variable is returned.
S7-1200 Programmable controller
452
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.5
Get_Name (Read the name of a PROFINET IO device)
The "Get_Name" instruction reads the name of a PROFINET IO device, PROFIBUS slave, or
AS-i slave. The name is displayed in the network view and in the properties of the IO device.
Table 9- 154 Get_Name instruction
LAD / FBD
SCL
"Get_Name_DB"(
LADDR:=_uint_in_,
STATION_NR:=_uint_in_,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
LEN=>_dint_out_,
STATUS=>_word_out_,
DATA:=_variant_inout_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "Get_Name_DB" is the name of the instance DB.
Description
Use the Get_Name instruction to read
the name of a PROFINET IO device
or PROFIBUS slave.
You select the IO device by using the hardware identifier of the distributed IO system (at the
LADDR parameter) and the device number of the PROFINET IO device or the PROFIBUS
address of the PROFIBUS slave (at the STATION_NR parameter).
Once the instruction has been executed, the program writes the name of the IO device to the
area addressed with the DATA parameter.
The name that is read depends on the type of IO device:
● DP slave or IO device: Name of the head module
● I-slave or I-device: Name of the interface module
● HMI panel: Name of the interface
● PC station: Name of the interface module
● GSD devices: Displays the name of the Device Access Point (DAP) (name of the
interface or head module)
The instruction writes the length of the name at the LEN parameter. If the name is longer
than the area specified at the DATA parameter, the program writes only that section which
corresponds to the maximum length of the addressed area.
The maximum length for a name is 128 characters.
Note
Name of the CPU readout (Version 1.1)
If you assign a "0" at each of the parameters LADDR and STATION_NR, the instruction
writes the name of the CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
453
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Parameters
The following table shows the parameters of the Get_Name instruction:
Parameter
Declaration
Data type
Description
LADDR
IN
HW_IOSYSTEM
Hardware identifier (HW-IoSystem) of the distributed IO system. The number is taken from the system constants or the
properties of the IO system.
STATION_NR
IN
UInt
•
PROFINET IO device: Device number is applied in the
Network view from the properties of the IO device under
"Ethernet addresses".
•
PROFIBUS slave: PROFIBUS address is applied in the
Network view from the properties of the PROFIBUS slave
under "PROFIBUS address".
DATA
IN_OUT
Variant
Pointer to the area where the name is written.
DONE
OUT
Bool
The instruction executes successfully. Name of the module
transfers to the area at the DATA parameter.
BUSY
OUT
Bool
Status parameter:
ERROR
OUT
Bool
•
0: Execution of the instruction complete.
•
1: Execution of the instruction not yet complete.
Status parameter:
•
0: No error
• 1: An error occurred during execution of the instruction.
The STATUS parameter contains detailed information.
LEN
OUT
DInt
Length of the name of the IO device (number of characters).
STATUS
OUT
Word
Status parameter: The parameter is only set for the duration of
one call. To display the status, you should therefore copy
STATUS to a free data area.
S7-1200 Programmable controller
454
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
STATUS parameter
Error code*
(W#16#...)
Explanation
0
No error
7000
No job in progress
7001
First call of the asynchronous Get_Name instruction. Execution of the instruction not yet complete (BUSY
= 1, DONE = 0).
7002
Additional call of the asynchronous Get_Name instruction. Execution of the instruction not yet complete
(BUSY = 1, DONE = 0).
8090
The hardware identifier specified at the LADDR parameter does not exist in the project.
8092
The value at the LADDR parameter does not address a PROFINET IO system.
8093
Instruction does not support data type at the DATA parameter.
8095
Device number (STATION_NR parameter) does not exist in the selected PROFINET IO system or does
not address an IO device.
80B1
The CPU used does not support the instruction.
80C3
Temporary resource error: The CPU is currently processing the maximum possible number of simultaneous block calls. Get_Name cannot be executed until at least one of the block calls is finished.
8852
The area specified at the DATA parameter is too short for the full name of the IO device. The name can be
written up to the maximum possible length.
To read the full name, use a longer data area at the DATA parameter. The area must have at least as
many characters as there are at the LEN parameter.
* The error codes in the program editor can be displayed as integer or hexadecimal values.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
455
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Example
The following example shows how you can read the station name of an ET 200SP
PROFINET IO device:
1. Configuring the ET 200SP:
– Create the ET 200SP with the station name "Conveyor_1" in the network view and
assign it to the same PROFINET IO system as the CPU.
– Assign the CPU as the IO controller for the ET 200SP.
– Use the default device number "1" located in the Properties under "Ethernet
addresses".
2. Assigning parameters for the Get_Name instruction:
– Enter the hardware ID of the IO system at the LADDR parameter. In this example, the
hardware ID is "269". You can find the hardware ID at the following location:
PLC tags > Show all tags > System constants tab > Local-PROFINET_IO-System
– Enter the device number of the ET 200SP at the STATION_NR parameter. In this
example, the device number is "1".
– Connect a tag with the data type STRING of a data block at the DATA parameter.
S7-1200 Programmable controller
456
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Note
When using the dropdown to make your selections for configuring the tag to the DATA
parameter, select the DB (in the example, "Datablock") and the tag (in the example,
"String[ ]"). In order to read the entire String data type, you must delete the brackets
so that the final result is: "Datablock".String
– Define PLC tags (memory area, flags) for the output parameters of the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
457
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
3. Executing the Get_Name instruction:
– As the instruction executes, the BUSY output parameter may get set to "1", and the
DONE parameter is then set to "0".
– Error code information is displayed at the STATUS output parameter.
S7-1200 Programmable controller
458
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
4. Completing execution of the Get_Name instruction:
– After execution of the instruction, the program writes "Conveyor_1", the station name
of the ET 200SP, into the data block at the DATA parameter.
– The program writes "10", the number of characters in the station name, to the LEN
parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
459
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.6
GetStationInfo (Read the IP or MAC address of a PROFINET IO device)
The "GetStationInfo" instruction reads the IP or MAC address of a PROFINET IO device in
the local IO system or a PROFINET IO device located in a lower-level IO system (connected
using CP/CM modules).
Note
You can only use the GetStationInfo instruction with PROFINET IO devices. You cannot use
the instruction with PROFIBUS DP slaves.
Table 9- 155 GetStationInfo instruction
LAD / FBD
SCL
"GetStationInfo_SFB_DB"(
REQ:=_bool_in_,
LADDR:=_uint_in_,
DETAIL:=_uint_in_,
MODE:=_uint_in_,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_,
DATA:=_variant_inout_);
Description
Use the GetStationInfo instruction to
read the IP or MAC address of a
PROFINET IO device. The instruction
also enables you to read the IP or
MAC address of an IO device located
in a lower-level IO system (connected
using CP/CM modules).
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "GetStationInfo_SFB_DB" is the name of the instance DB.
You address the IO device using the hardware identifier of the station at the LADDR
parameter. You can find the hardware ID at the following location:
PLC tags > Show all tags > System constants tab. Search for the "IODevice" in the Name
column and for "Hw_Device" in the Data type column.
Use the MODE parameter to select the information to be read.
At the DATA parameter, assign the data area to which the instruction writes the read
address data. For storing the IP address, use the "IF_CONF_v4" structure. For storing the
MAC address, use the "IF_CONF_MAC" structure.
Enable reading of the address data using the REQ control parameter. This requires the IO
device to be accessible.
S7-1200 Programmable controller
460
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
The instruction displays the execution status of the read job using the BUSY, DONE, and
ERROR output parameters and the STATUS output parameter.
Note
Address the IO device using only the hardware identifier of the station
The station, the IO device, and PROFINET interface have their own hardware identifier. Use
only the hardware identifier of the station for the GetStationInfo instruction.
If a PROFINET interface is addressed using the LADDR parameter, for example, the
address data is not read and the CPU generates a "8092" error code.
To read the address data of an integrated PROFINET interface or a CM/CP module in the
central configuration, use the "RDREC" instruction.
Parameters
The following table shows the parameters of the GetStationInfo instruction:
Parameter
Declaration
Data type
Description
REQ
IN
Bool
Control parameter request
LADDR
IN
HW_DEVICE
Hardware identifier of the station of the IO device
Activates the reading of the information with REQ = "1".
The number is taken from the properties of the station in the
Network view or from the "System constants" tab of the default
tag table.
DETAIL
IN
HW_SUBMODUL The DETAIL parameter is not used. Leave the parameter unE
connected.
MODE
IN
UNIT
Selection of address data to be read:
•
MODE = 1: Address parameter according to IPv4 (S7-1200
CPUs as of firmware version V4.2)
•
MODE = 2: MAC address (S7-1200 CPUs as of firmware
version V4.2)
DATA
IN_OUT
Variant
Pointer to the area to which the program writes the address
data of the IO device. Use the "IF_CONF_v4" structure for
MODE = 1, and the "IF_CONF_MAC" structure for MODE = 2.
DONE
OUT
Bool
The program executed the instruction successfully. The program transferred the address data to the DATA parameter.
BUSY
OUT
Bool
STATUS parameter:
•
0: Execution of the instruction complete.
•
1: Execution of the instruction not yet complete.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
461
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Parameter
Declaration
Data type
Description
ERROR
OUT
Bool
STATUS parameter:
•
0: No error.
• 1: An error occurred during execution of the instruction.
Detailed information is output using the STATUS parameter.
STATUS
OUT
Word
STATUS parameter:
The parameter is only set for the duration of one call. To display the status, you should therefore copy STATUS to a free
data area.
DATA parameter
● Use the "IF_CONF_v4" structure at the DATA parameter to store the address parameter
according to IPv4:
Byte
Parameter
Data type
Start value
Description
0…1
Id
UINT
30
ID of the "IF_CONF_v4" structure
2…3
Length
UNIT
18
Length of data read in BYTE
4 ... 5
Mode
UNIT
0
Not relevant for the "GetStationInfo" instruction (left at
"0")
6 ... 9
InterfaceAddress
ARRAY [1..4] of
BYTE
-
IP address of the IO device in the format IP_V4 (for
example, 192.168.3.10):
10 …
13
14 ...
17
SubnetMask
DefaultRouter
ARRAY [1..4] of
BYTE
ARRAY [1..4] of
BYTE
-
-
•
addr[1] = 192
•
addr[2] = 168
•
addr[3] = 3
•
addr[4] = 10
Subnet mask of the IO device in the format IP_V4 (for
example, 255.255.255.0):
•
addr[1] = 255
•
addr[2] = 255
•
addr[3] = 255
•
addr[4] = 0
IP address of the router in the format IP_V4 (for example, 192.168.3.1):
•
addr[1] = 192
•
addr[2] = 168
•
addr[3] = 3
•
addr[4] = 1
S7-1200 Programmable controller
462
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
● Use the "IF_CONF_MAC" structure at parameter DATA for storing the MAC address:
Byte
Parameter
Data type
Start value
Description
0…1
Id
UINT
3
ID of the "IF_CONF_MAC" structure
2…3
Length
UNIT
12
Length of data read in BYTE
4 ... 5
Mode
UNIT
0
Not relevant for the "GetStationInfo" instruction (left at
"0")
6 ... 11
MACAddress
ARRAY [1..6] of
BYTE
-
MAC address of the IO device (for example, 08-00-0612-34-56):
•
Mac[1] = 8
•
Mac[2] = 0
•
Mac[3] = 6
•
Mac[4] = 12
•
Mac[5] = 34
•
Mac[6] = 56
STATUS parameter
Error code*
(W#16#...)
Explanation
0
No error
7000
No job in progress
7001
First call of the asynchronous instruction GetStationInfo. Execution of the instruction not yet complete
(BUSY = 1, DONE = 0).
7002
Additional call of the asynchronous instruction GetStationInfo. Execution of the instruction not yet complete (BUSY = 1, DONE = 0).
8080
Value at the MODE parameter is not supported.
8090
The hardware identifier specified at the LADDR parameter is not configured.
8092
The LADDR parameter does not address a PROFINET IO device.
8093
Invalid data type at the DATA parameter.
80A0
Requested information is not read.
80C0
Addressed IO device is not reachable.
80C3
The maximum number of simultaneous calls of the GetStationInfo instruction (10 instances) has been
reached.
* The error codes in the program editor are displayed as integer or hexadecimal values.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
463
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Example
In the example below, you use the GetStationInfo instruction to read the IP address data of
an IO device and write the information to a data block. The IP address data includes the
IP address, subnet mask, and (if used) the address data of the router.
The IO controller executes the GetStationInfo instruction, and the instruction reads the
IP address information of a lower-level IO device (in this example, an ET200SP):
1. Configuring the ET 200SP:
– Create the ET 200SP with the station name "Conveyor_1" in the network view, and
assign it to the same PROFINET IO system as the CPU.
– Assign the CPU as the IO controller for the ET 200SP.
S7-1200 Programmable controller
464
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
2. Assigning parameters for the GetStationInfo instruction:
– Create five tags and a structure with the IF_CONF_v4 data type in a global data block
for storing the IP address data. Assign any name to the structure. (In the example, the
structure name is "IP_Address".)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
465
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
3. Assigning parameters for the GetStationInfo instruction:
– Enter the hardware ID of the IO device at the LADDR parameter. The hardware
identifier uniquely identifies the product, and, in this example, the hardware ID is
"270". You can find the hardware ID at the following location: PLC tags > Show all
tags > System constants tab
Search for the IO device in the Name column and for the "Hw_Device" in the Data
type column. The associated value is the hardware ID that you enter at the LADDR
parameter.
– Select "1" (read address parameters according to IPv4) for the MODE parameter.
– Connect the IF_CONF_v4 structure at the DATA parameter.
Note
When using the dropdown list to make your selections for configuring the tag to the
DATA parameter, select the DB (in the example, "GetStationInfo_Global_DB") and the
tag (in the example, "IP address"). In order to read the entire IF_CONF_v4 data type,
you must delete the period that appears following "IP address" so that the final result
is: "GetStationInfo_Global_DB".IP address
– Define PLC tags from your global DB for the output parameters of the instruction.
S7-1200 Programmable controller
466
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
4. Executing the GetStationInfo instruction:
– When the REQ input = 1 (FALSE), the instruction displays no IP address information
at the DATA input/output parameter or error code information at the STATUS output
parameter.
5. Completing execution of the GetStationInfo instruction:
– When the REQ input = 1 (TRUE), the program executes the instruction and writes the
IP address to the data block. The program writes the IP address, "C0 A8 02 1A"
(decimal value of "192.168.2.26"), to the DATA input/output parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
467
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.7
DeviceStates instruction
You can use the DeviceStates instruction to return the states of all distributed I/O slave
devices connected to a specified distributed I/O Master.
Table 9- 156 DeviceStates instruction
LAD / FBD
SCL
ret_val := DeviceStates(
laddr:=_word_in_,
mode:=_uint_in_,
state:=_variant_inout_);
Description
DeviceStates retrieves the I/O device operational states of an I/O subsystem. After execution, the STATE parameter contains the error
state of each I/O device in a bit list (for the
assigned LADDR and MODE). This information
corresponds with the device status seen in the
STEP 7 diagnostics view.
The LADDR input of DeviceStates uses the
hardware identifier of a distributed I/O interface.
In the TIA portal, the hardware identifiers for a
PLC can be found by looking for
"HW_IOSYSTEM" data types in the system
constants tab in the PLC tag table.
Table 9- 157 Data types for the parameters
1
Parameter and type
Data type
Description
LADDR
IN
HW_IOSYSTEM
Logical address: (Identifier for the I/O system)
MODE
IN
UInt
Supports five modes of operation. The MODE input determines
which data will be returned to the location specified for STATE
information. The modes are as follows:
•
1: Device configuration active
•
2: Device defective
•
3: Device disabled
•
4: Device exists
•
5: Problem in Device
RET_VAL
OUT
Int
Execution condition code
STATE1
InOut
Variant
Buffer that receives the error status of each device: The data type
that you choose for the STATE parameter can be any bit type
(Bool, Byte, Word, or DWord) or an array of a bit type
•
Bit 0 of the first byte of the returned STATE data is a summary
bit. When it is set to TRUE, it indicates that other data is available.
•
The data returned by the STATE parameter shows a one-toone correlation between a bit location and a distributed I/O address. This device addressing is TRUE for PROFIBUS and
PROFINET. For example, Bit 4 in the first Byte correlates to
PROFIBUS address 4 or PROFINET device number 4.
For PROFIBUS-DP, the length of the status information is 128 bits. For PROFINET I/O, the length is 1024 bits.
S7-1200 Programmable controller
468
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
After execution, the STATE parameter contains the error state of each I/O device as a bit list
(for the assigned LADDR and MODE).
Table 9- 158 Condition codes
RET_VAL (W#16#...)
Description
0
No error
8091
LADDR does not exist.
8092
LADDR does not address an I/O system.
8093
Invalid data type assigned for STATE parameter: Valid data types are (Bool, Byte, Word, or
Dword), or an array of (Bools, Bytes, Words, or Dwords)
80Bx
DeviceStates instruction not supported by the CPU for this LADDR.
8452
The complete state data is too large for the assigned STATE parameter. The STATE buffer
contains a partial result.
9.7.7.1
DeviceStates example configurations
PROFIBUS example
The PROFIBUS example consists of the following:
● 16 PROFIBUS devices named "DPSlave_10" through "DPSlave_25"
● The 16 PROFIBUS devices use PROFIBUS addresses 10 through 25, respectively.
● Each slave device is configured with multiple I/O modules.
● The first four bytes of the returned STATE parameter information is displayed.
MODE
Example 1:
Normal operation with
no errors
Example 2:
PROFIBUS slave device DPSlave_12 with
single module pulled
Example 3:
PROFIBUS slave
device DPSlave_12
disconnected
1: Device configuration
active
0x01FC_FF03
0x01FC_FF03
0x01FC_FF03
2: Device defective
0x0000_0000
0x0110_0000
0x0110_0000
3: Device disabled
0x0000_0000
0x0000_0000
0x0000_0000
4: Device exists
0x01FC_FF03
0x01FC_FF03
0x01EC_FF03
5: Problem in device
0x0000_0000
0x0110_0000
0x0110_0000
The following four tables show a binary breakdown of the four bytes of data that are being
analyzed:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
469
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 159 Example 1: No errors: A value of 0x01FC_FF03 is returned for MODE 1 (Device configuration active).
Byte with value
Bit pattern with value
Byte 1 0x01
Bit 7 0000-0001 Bit 0
Byte 2 0xFC
Bit 15 1111-1100 Bit 8
Byte 3 0xFF
Bit 23 1111-1111 Bit 16
Byte 4 0x03
Bit 31 0000-0011 Bit 24
Notes
Bit 0 is true; data is available.
The devices are configured in addresses 10 (Bit 10) through 25 (Bit 25).
No devices are configured in addresses 1 through 9.
MODE 4 (Device exists) data matches MODE 1 (Device configuration active), so the configured
devices match the existing devices.
Table 9- 160 Example 2: A module has been pulled from PROFIBUS slave device "DPSlave_12". A
value of 0x0110_0000 is returned for MODE 2 (Device defective).
Byte with value
Bit pattern with value
Byte 1 0x01
Bit 7 0000-0001 Bit 0
Byte 2 0x10
Bit 15 0001-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Device 12 (Bit 12) is marked as defective.
MODE 5 (Problem in device) returns the same information as MODE 2 (Device defective).
S7-1200 Programmable controller
470
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 161 Example 2 (continued): A module has been pulled from PROFIBUS slave device
"DPSlave_12". A value of 0x01FC_FF03 is returned for MODE 4 (Device exists).
Byte with value
Bit pattern with value
Byte 1 0x01
Bit 7 0000-0001 Bit 0
Byte 2 0xFC
Bit 15 1111-1100 Bit 8
Byte 3 0xFF
Bit 23 1111-1111 Bit 16
Byte 4 0x03
Bit 31 0000-0011 Bit 24
Notes
Bit 0 is true; data is available.
Even though device 12 (Bit 12) has an error as shown in MODE 2 (Device defective) above, the device is still functioning on the network which causes MODE 4 (Device exists) to show the device as
an "existing device".
Table 9- 162 Example 3: PROFIBUS slave device "DPSlave_12" is disconnected (cable disconnected
or power loss) from the PROFIBUS network. "DPSlave_12" is still detected as a defective device as well as an error in the device. The difference is that "DPSlave_12" is no
longer detected as a device that exists. A value of 0x01EC_FF03 is returned for MODE 4
(Device exists).
Byte with value
Bit pattern with value
Byte 1 0x01
Bit 7 0000-0001 Bit 0
Byte 2 0xEC
Bit 15 1110-1100 Bit 8
Byte 3 0xFF
Bit 23 1111-1111 Bit 16
Byte 4 0x03
Bit 31 0000-0011 Bit 24
Notes
Bit 0 is true; data is available.
Device 12 (Bit 12) is marked as not existing. With this exception, devices 10 through 25 still report as
existing.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
471
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
PROFINET example
The PROFINET example consists of the following:
● 16 PROFINET slave devices named "et200s_1" through "et200s_16"
● The 16 PROFINET devices use PROFINET device numbers 1 through 16, respectively.
● Each slave device is configured with multiple I/O modules.
● The first four bytes of the returned STATE parameter information is displayed.
MODE
Example 1:
Normal operation with
no errors
Example 2:
PROFINET slave
et200s_1 module
pulled
Example 3:
PROFINET slave
et200s_1 disconnected
1: Device configuration
active
0xFFFF_0100
0xFFFF_0100
0xFFFF_0100
2 - Device defective
0x0000_0000
0x0300_0000
0x0300_0000
3 - Device disabled
0x0000_0000
0x0000_0000
0x0000_0000
4 - Device exists
0xFFFF_0100
0xFFFF_0100
0xFDFF_0100
5 - Problem in device
0x0000_0000
0x0300_0000
0x0300_0000
The following four tables show a binary breakdown of the four bytes of data that are being
analyzed:
Table 9- 163 Example 1: No errors: A value of 0xFFFF_0100 is returned for MODE 1 (Device configuration active).
Byte with value
Bit pattern with value
Byte 1 0xFF
Bit 7 1111-1111 Bit 0
Byte 2 0xFF
Bit 15 1111-1111 Bit 8
Byte 3 0x01
Bit 23 0000-0001 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
The devices are configured in addresses 1 (Bit 1) through 16 (Bit 16).
No devices are configured in addresses 1 through 9.
MODE 4 (Device exists) data matches MODE 1 (Device configuration active), so the configured
devices match the existing devices.
S7-1200 Programmable controller
472
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 164 Example 2: A module has been pulled from PROFINET slave device "et200s_1". A value
of 0x0300_0000 is returned for MODE 2 (Device defective).
Byte with value
Bit pattern with value
Byte 1 0x03
Bit 7 0000-0011 Bit 0
Byte 2 0x00
Bit 15 0000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Device 1 (Bit 1) is marked as defective. Since the device still exists, MODE 4 (Device exists) shows
the same data as when operating normally.
MODE 5 (Problem in device) returns the same information as MODE 2 (Device defective).
Table 9- 165 Example 2 (continued): A module has been pulled from PROFIBUS slave device
"et200s_1". A value of 0xFFFF_0100 is returned for MODE 4 (Device exists).
Byte with value
Bit pattern with value
Byte 1 0xFF
Bit 7 1111-1111 Bit 0
Byte 2 0xFF
Bit 15 1111-1111 Bit 8
Byte 3 0x01
Bit 23 0000-0001 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Even though device 1 (Bit 1) has an error as shown in MODE 2 (Device defective) above, the device
is still functioning on the network which causes MODE 4 (Device exists) to show the device as an
"existing device".
Table 9- 166 Example 3: PROFINET slave device "et200s_1" is disconnected (cable disconnected or
power loss) from the PROFINET network. A value of 0xFDFF_0100 is returned for
MODE 4 (Device exists).
Byte with value
Bit pattern with value
Byte 1 0xFD
Bit 7 1111-1101 Bit 0
Byte 2 0xFF
Bit 15 1111-1111 Bit 8
Byte 3 0x01
Bit 23 0000-0001 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Device 1 (Bit 1) does not exist. Devices 2 (Bit 2) through 16 (Bit 16) do exist.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
473
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.8
ModuleStates instruction
You can use the ModuleStates instruction to return the status of all of the modules in a
PROFIBUS or PROFINET station.
Table 9- 167 ModuleStates instruction
LAD / FBD
SCL
ret_val := ModuleStates(
laddr:=_word_in_,
mode:=_uint_in,
state:=_variant_inout);
Description
ModuleStates retrieves the operational states
of I/O modules. After execution, the STATE
parameter contains the error state of each I/O
module in a bit list (for the assigned LADDR
and MODE). This information corresponds
with the module status seen in the STEP 7
diagnostics view.
The LADDR input of ModuleStates uses is a
hardware identifier of a distributed I/O station
and not of the head module itself. The hardware identifier can be found by selecting the
entire station in the network view and then
looking in the hardware identifier section under properties. It can also be found by looking
for "Hw_Device" and "Hw_DpSlave" data
types in the system constants tab in the PLC
tag table.
S7-1200 Programmable controller
474
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 168 Data types for the parameters
Parameter and type
Data type
Description
LADDR
IN
HW_DEVICE
Logical address (Identifier for the I/O modules)
MODE
IN
UInt
Supports five modes of operation. The MODE input determines
which data will be returned to the location specified for STATE
information. The modes are as follows:
•
1: Module configuration active
•
2: Module defective
•
3: Module disabled
•
4: Module exists
•
5: Problem in Module
RET_VAL
OUT
Int
Status (condition code)
STATE1
InOut
Variant
Buffer that receives the error status of each module: The data type
you use for the STATE parameter can be any bit type (Bool, Byte,
Word, or DWord) or an array of a bit type.
•
Bit 0 of the first byte of the returned STATE data is a summary
bit. When it is set to TRUE, it indicates that other data is available.
•
The data returned by the STATE parameter shows a one-toone correlation between a bit location and a module position.
This slot addressing is TRUE for PROFIBUS and PROFINET.
For example, for an ET 200SP with a head module, power
module, and a pair of I/O modules, Bit 1 in the first Byte correlates to the head module, Bit 2 to the power module, and Bits 3
and 4 to the I/O modules, respectively.
A maximum of 128 bits can be assigned. The number of bits required is dependent on your I/O module usage.
1
Table 9- 169 Condition codes
RET_VAL ( W#16#...)
Description
0
No error
8091
Module identified by LADDR does not exist.
8092
Module identified by LADDR does not address an I/O device.
8093
Invalid data type for STATE parameter: Valid data types are (Bool, Byte, Word, or Dword), or
an array of (Bools, Bytes, Words, or Dwords).
80Bx
ModuleStates instruction not supported by this CPU for this LADDR.
8452
The complete state data is too large for the assigned STATE parameter. The STATE buffer
contains a partial result.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
475
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.8.1
ModuleStates example configurations
PROFIBUS example
The PROFIBUS example consists of the following:
● 16 PROFIBUS devices named "DPSlave_10" through "DPSlave_25"
● The 16 PROFIBUS devices use PROFIBUS addresses 10 through 25, respectively.
● Each slave device is configured with multiple I/O modules.
● The example uses the LADDR parameter of PROFIBUS slave "DPSlave_12" which
contains a head module, a power module, and two I/O modules.
● The first four bytes of the returned STATE parameter information is displayed.
MODE
Example 1:
Normal operation with
no errors
Example 2:
PROFIBUS slave device DPSlave_12 module pulled
Example 3:
PROFIBUS slave
device DPSlave_12
disconnected
1: Module configuration
active
0x1F00_0000
0x1F00_0000
0x1F00_0000
2: Module defective
0x0000_0000
0x0900_0000
0x1F00_0000
3: Module disabled
0x0000_0000
0x0000_0000
0x0000_0000
4: Module exists
0x1F00_0000
0x1700_0000
0x0000_0000
5: Problem in module
0x0000_0000
0x0900_0000
0x1F00_0000
The following four tables show a binary breakdown of the four bytes of data that are being
analyzed:
Table 9- 170 Example 1: No errors: A value of 0x1F00_0000 is returned for MODE 1 (Module configuration active).
Byte with value
Bit pattern with value
Byte 1 0x1F
Bit 7 0001-1111 Bit 0
Byte 2 0x00
Bit 15 0000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Slots 1 (Bit 1) through 4 (Bit 4) contain modules. Slots 5 (Bit 5) and beyond do not contain modules.
MODE 4 (Module exists) data matches MODE 1 (Module configuration active), so the configured
modules match the existing modules.
S7-1200 Programmable controller
476
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 171 Example 2: A module has been pulled from PROFIBUS slave device "DPSlave_12". A
value of 0x0900_0000 is returned for MODE 2 (Module defective).
Byte with value
Bit pattern with value
Byte 1 0x09
Bit 7 0000-1001 Bit 0
Byte 2 0x00
Bit 15 0000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Only module 3 (Bit 3) is marked as defective. All other modules are functional.
Table 9- 172 Example 2 (continued): A module has been pulled from PROFIBUS slave device
"DPSlave_12". A value of 0x1700_0000 is returned for MODE 4 (Module exists).
Byte with value
Bit pattern with value
Byte 1 0x17
Bit 7 0001-0111 Bit 0
Byte 2 0x00
Bit 15 0000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Module 3 (Bit 3) is shown as missing. Modules 1, 2, and 4 (Bits 1, 2, and 4) are shown as existing.
Table 9- 173 Example 3: PROFIBUS slave device "DPSlave_12" is disconnected (cable disconnected
or power loss) from the PROFIBUS network. A value of 0x1F00_0000 is returned for
MODE 2 (Module defective).
Byte with value
Bit pattern with value
Byte 1 0x1F
Bit 7 0001-1111 Bit 0
Byte 2 0x00
Bit 15 0000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
The modules in slots 1 through 4 (Bits 1 through 4) are all marked as defective since the device is
missing.
MODE 5 (Problem in module) shows the same information as MODE 2 (Module defective).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
477
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
PROFINET example
The PROFINET example consists of the following:
● 16 PROFINET slave devices named "et200s_1" through "et200s_16"
● The 16 PROFINET devices use PROFINET device numbers 1 through 16, respectively.
● Each slave device is configured with multiple I/O modules.
● The example uses PROFINET slave "et200s_1" which contains a head module, a power
module, and 18 I/O modules.
● The first four bytes of the returned STATE parameter information is displayed.
MODE
Example 1:
Normal operation with
no errors
Example 2:
PROFINET et200s_1
slave module pulled
Example 3:
PROFINET et200s_1
slave disconnected
1: Module configuration
active
0xFFFF_1F00
0xFFFF_1F00
0xFFFF_1F00
2: Module defective
0x0000_0000
0x0180_0000
0xFFFF_1F00
3: Module disabled
0x0000_0000
0x0000_0000
0x0000_0000
4: Module exists
0xFFFF_1F00
0xFF7F_1F00
0x0000_0000
5: Problem in module
0x0000_0000
0x0180_0000
0xFFFF_1F00
The following four tables show a binary breakdown of the four bytes of data that are being
analyzed:
Table 9- 174 Example 1: No errors: A value of 0xFFFF_1F00 is returned for MODE 1 (Module configuration active).
Byte with value
Bit pattern with value
Byte 1 0xFF
Bit 7 1111-1111 Bit 0
Byte 2 0xFF
Bit 15 1111-1111 Bit 8
Byte 3 0x1F
Bit 23 0001-1111 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Slots 1 (Bit 1) through 20 (Bit 20) contain modules. Slot 21 (Bit 21) and beyond do not contain modules.
MODE 4 (Module exists) data matches MODE 1 (Module configuration active), so the configured
modules match the existing modules.
Table 9- 175 Example 2: A module has been pulled from PROFINET slave device "et200s_1". A value
of 0x0180_0000 is returned for MODE 2 (Module defective).
Byte with value
Bit pattern with value
Byte 1 0x01
Bit 7 0000-0001 Bit 0
Byte 2 0x80
Bit 15 1000-0000 Bit 8
Byte 3 0x00
Bit 23 0000-0000 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Only module 15 (Bit 15) is marked as defective. All other modules are functional.
S7-1200 Programmable controller
478
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Table 9- 176 Example 2 (continued): A module has been pulled from PROFIBUS slave device
"et200s_1". A value of 0xFF7F_1F00 is returned for MODE 4 (Module exists).
Byte with value
Bit pattern with value
Byte 1 0xFF
Bit 7 1111-1111 Bit 0
Byte 2 0x7F
Bit 15 0111-1111 Bit 8
Byte 3 0x1F
Bit 23 0001-1111 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
Module 15 (Bit 15) is shown as missing. Modules 1 through 14 (Bits 1 through 14) and 16 through 20
(Bits 16 through 20) are shown as existing.
Table 9- 177 Example 3: PROFINET slave device "et200s_1" is disconnected (cable disconnected or
power loss) from the PROFINET network. A value of 0xFFFF_1F00 is returned for
MODE 2 (Module defective).
Byte with value
Bit pattern with value
Byte 1 0xFF
Bit 7 1111-1111 Bit 0
Byte 2 0xFF
Bit 15 1111-1111 Bit 8
Byte 3 0x1F
Bit 23 0001-1111 Bit 16
Byte 4 0x00
Bit 31 0000-0000 Bit 24
Notes
Bit 0 is true; data is available.
The modules in slots 1 through 20 (Bits 1 through 20) are all marked as defective since the device is
missing.
MODE 5 (Problem in module) shows the same information as MODE 2 (Module defective).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
479
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
9.7.9
GET_DIAG (Read diagnostic information)
Description
You can use the "GET_DIAG" instruction to read out the diagnostic information of a
hardware device. The hardware device is selected with the LADDR parameter. With the
MODE parameter, you select which diagnostic information to read.
Table 9- 178 GET_DIAG instruction
LAD / FBD
SCL
ret_val := GET_DIAG(
mode:=_uint_in_,
laddr:=_word_in_,
cnt_diag=>_uint_out_,
diag:=_variant_inout_,
detail:=_variant_inout_);
Description
Reads the diagnostic information from an
assigned hardware device.
Parameters
The following table shows the parameters of the "GET_DIAG" instruction:
Table 9- 179 Data types for the parameters
Parameter and type
Data type
Description
MODE
IN
UInt
Use the MODE parameter to select which diagnostic data is to be
output.
LADDR
IN
HW_ANY (Word)
Hardware ID of the device
RET_VAL
OUT
Int
Status of the instruction
CNT_DIAG
OUT
UInt
Number of output diagnostic details
DIAG
InOut
Variant
Pointer to data area for storage of diagnostic information of the selected mode
DETAILS
InOut
Variant
Pointer to data area for storage of diagnostic details in accordance
with the selected mode
S7-1200 Programmable controller
480
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
MODE parameter
Depending on the value at the MODE parameter, different diagnostics data is output at the
DIAG, CNT_DIAG and DETAILS output parameters:
Table 9- 180 MODE parameter
MODE
Description
DIAG
CNT_DIAG
DETAILS
0
Output of all supported diagnostic information for a module as DWord, where Bit X=1
indicates that mode X is supported.
Bit string of the supported
0
modes as DWord, where Bit
X=1 indicates that mode X
is supported.
-
1
Output of the inherent status
of the addressed hardware
object.
Diagnostics status: Output
in accordance with the DIS
structure. (Note: Refer to
the "DIS structure" information below and
GET_DIAG instruction example at the end of the
section.)
0
-
2
Output of the status of all
subordinate modules of the
addressed hardware object.
Output of diagnostics data
0
in accordance with the DNN
structure. (Note: Refer to
the "DNN structure" information below and
GET_DIAG instruction example at the end of the
section.)
-
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
481
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
DIS structure
With the MODE parameter = 1, the diagnostics information is output in accordance with the
DIS structure. The following table shows the meaning of the individual parameter values:
Table 9- 181 Structure of the Diagnostic Information Source (DIS)
Parameter
Data type
Value
MaintenanceState
DWord
Enum
Componentstate
Detail
DWord
Description
0
No maintenance required
1
The module or device is disabled.
2
-
3
-
4
-
5
Maintenance required
6
Maintenance demanded
7
Error
8
Status unknown / error in subordinate module
9
-
10
Inputs/outputs are not available.
Bit array
Status of the module submodules:
0 to 2
(enum)
•
Bit 0 to 15: Status message of the module
•
Bit 16 to 31: Status message of the CPU
Additional information:
•
Bit 0: No additional information
•
Bit 1: Transfer not permitted
3
Bit 3 = 1: At least one channel supports qualifiers for diagnostics.
4
Bit 4 = 1: Maintenance required for at least one channel or one component
5
Bit 5 = 1: Maintenance demanded for at least one channel or one component
6
Bit 6 = 1: Error in at least one channel or one component
7 to 10
Reserved (always = 0)
11 to 14
Bit 11 = 1: PNIO - submodule correct
Bit 12 = 1: PNIO - replacement module
Bit 13 = 1: PNIO - incorrect module
Bit 14 = 1: PNIO - module disconnected
15
Reserved (always = 0)
S7-1200 Programmable controller
482
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Parameter
Data type
Value
Description
16 to 31
Status information for modules generated by the CPU:
Bit 16 = 1: Module disabled
Bit 17 = 1: CiR operation active
Bit 18 = 1: Input not available
Bit 19 = 1: Output not available
Bit 20 = 1: Overflow diagnostics buffer
Bit 21 = 1: Diagnostics not available
Bit 22 - 31: Reserved (always 0)
OwnState
IO State
OperatingState
Uint16
Uint16
UInt16
Enum
The value of the OwnState parameter describes the maintenance status of the module.
0
No fault
1
The module or device is disabled.
2
Maintenance required
3
Maintenance demanded
4
Error
5
The module or the device cannot be reached from the CPU (valid for
modules and devices below a CPU).
6
Inputs/outputs are not available.
7
-
Bit array
I/O status of the module
0
Bit 0 = 1: No maintenance required
1
Bit 1 = 1: The module or device is disabled.
2
Bit 2 = 1: Maintenance required
3
Bit 3 = 1: Maintenance demanded
4
Bit 4 = 1: Error
5
Bit 5 = 1: The module or the device cannot be reached from the CPU
(valid for modules and devices below a CPU).
6
Qualifier; bit 7 = 1, if bit 0, 2, or 3 are set
7
Inputs/outputs are not available.
8 to 15
Reserved (always = 0)
Enum
0
-
1
In STOP / firmware update
2
In STOP / reset memory
3
In STOP / self start
4
In STOP
5
Memory reset
6
In START
7
In RUN
8
-
9
In HOLD
10
-
11
-
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
483
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Parameter
Data type
Value
Description
12
Module defective
13
-
14
No power
15
CiR
16
In STOP / without DIS
17
In
18
19
20
DNN structure
With the MODE parameter = 2, the diagnostics information details are output in accordance
with the DNN structure. The following table shows the meaning of the individual parameter
values:
Table 9- 182 Structure of the Diagnostic Navigation Node (DNN)
Parameter
Data type
Value
Description
SubordinateState
UINT
Enum
Status of the subordinate module (See parameter OwnState of
the DIS structure.)
SubordinateIOState
WORD
Bitarray
Status of the inputs and outputs of the subordinate module (See
parameter IO State of the DIS structure.)
DNNmode
WORD
Bitarray
•
Bit 0 = 0: Diagnostics enabled
•
Bit 0 = 1: Diagnostics disabled
•
Bit 1 to 15: Reserved
RET_VAL parameter
Table 9- 183 Error codes of the RET_VAL parameter
Error code
Description
(W#16#...)
0
No error
8080
Value in the MODE parameter is not supported.
8081
Type in the DIAG parameter is not supported with the selected mode (parameter MODE).
8082
Type in the DETAILS parameter is not supported with the selected mode (parameter MODE).
8090
LADDR does not exist.
8091
The selected channel in the CHANNEL parameter does not exist.
80C1
Insufficient resources for parallel execution
S7-1200 Programmable controller
484
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Example
The following ladder logic network and DB show how to use the three modes with the three
structures:
● DIS
● DNN
①
②
DNN
DIS
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
485
Extended instructions
9.7 Diagnostics (PROFINET or PROFIBUS)
Note
In the DB, you must manually type in the data type to access each of the three structures;
there is no dropdown list selection. Type in the data types exactly as shown below:
• DNN
• DIS
9.7.10
Diagnostic events for distributed I/O
Note
With a PROFIBUS IO system, after a download or power cycle, the CPU will go to RUN
mode unless the hardware compatibility is set to allow acceptable substitute modules
(Page 170) and one or more modules is missing or is not an acceptable substitute for the
configured module.
As shown in the following table, the CPU supports diagnostics that can be configured for the
components of the distributed I/O system. Each of these errors generates a log entry in the
diagnostic buffer.
Table 9- 184 Handling of diagnostic events for PROFINET and PROFIBUS
Type of error
Diagnostic information for
the station?
Entry in the diagnostic buffer?
CPU operating mode
Diagnostic error
Yes
Yes
Stays in RUN mode
Rack or station failure
Yes
Yes
Stays in RUN mode
I/O access error 1
No
Yes
Stays in RUN mode
No
Yes
Stays in RUN mode
Yes
Yes
Stays in RUN mode
Peripheral access error
Pull / plug event
2
1
I/O access error example cause: A module that has been removed.
2
Peripheral access error example cause: Acyclic communication to a submodule that is not communicating.
Use the GET_DIAG instruction (Page 480) for each station to obtain the diagnostic
information. This will allow you to programmatically handle the errors encountered on the
device and if desired take the CPU to STOP mode. This method requires you to specify the
hardware device from which to read the status information.
The GET_DIAG instruction uses the "L address" (LADDR) of the station to obtain the health
of the entire station. This L Address can be found within the Network Configuration view and
by selecting the entire station rack (entire gray area), the L Address is shown in the
Properties Tab of the station. You can find the LADDR for each individual module either in
the properties for the module (in the device configuration) or in the default tag table for the
CPU.
S7-1200 Programmable controller
486
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
9.8
Pulse
9.8.1
CTRL_PWM (Pulse width modulation)
Table 9- 185 CTRL_PWM (Pulse Width Modulation) instruction
LAD / FBD
SCL
"CTRL_PWM_DB"(
PWM:=_uint_in_,
ENABLE:=_bool_in_,
BUSY=>_bool_out_,
STATUS=>_word_out_);
Description
Provides a fixed cycle time output with a variable duty
cycle. The PWM output runs continuously after being
started at the specified frequency (cycle time). The
pulse width is varied as required to affect the desired
control.
1
When you insert the instruction, STEP 7 displays the "Call Options" dialog for creating the associated DB.
2
In the SCL example, "CTRL_PWM_DB" is the name of the instance DB.
Table 9- 186 Data types for the parameters
Parameter and type
Data type
Description
PWM
IN
HW_PWM
(Word)
PWM identifier: Names of enabled pulse generators will become tags in
the "constant" tag table, and will be available for use as the PWM parameter. (Default value: 0)
ENABLE
IN
Bool
1=start pulse generator
BUSY
OUT
Bool
Function busy (Default value: 0)
STATUS
OUT
Word
Execution condition code (Default value: 0)
0 = stop pulse generator
The CTRL_PWM instruction stores the parameter information in the DB. The data block
parameters are not separately changed by the user, but are controlled by the CTRL_PWM
instruction.
Specify the enabled pulse generator to use, by using its tag name for the PWM parameter.
When the EN input is TRUE, the PWM_CTRL instruction starts or stops the identified PWM
based on the value at the ENABLE input. Pulse width is specified by the value in the
associated Q word output address.
Because the CPU processes the request when the CTRL_PWM instruction is executed,
parameter BUSY will always report FALSE. If an error is detected, then ENO is set to
FALSE, and parameter STATUS contains a condition code.
The pulse width will be set to the initial value configured in device configuration when the
CPU first enters RUN mode. You write values to the Q-word location specified in device
configuration ("Output addresses" / "Start address:") as needed to change the pulse width.
You use an instruction such as a move, convert, math, or PID box to write the desired pulse
width to the appropriate Q word. You must use the valid range for the Q-word value (percent,
thousandths, ten-thousandths, or S7 analog format).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
487
Extended instructions
9.8 Pulse
Note
Digital I/O points assigned to PWM and PTO cannot be forced
The digital I/O points used by the pulse-width modulation (PWM) and pulse-train output
(PTO) devices are assigned during device configuration. When digital I/O point addresses
are assigned to these devices, the values of the assigned I/O point addresses cannot be
modified by the Watch table force function.
Table 9- 187 Value of the STATUS parameter
STATUS
Description
0
No error
80A1
PWM identifier does not address a valid PWM.
9.8.2
CTRL_PTO (Pulse train output)
The PTO instruction provides a square wave with a 50% duty cycle output at a specified
frequency. You can use the CTRL_PTO instruction to assign the frequency without a
Technology objects (TO) axis data block (DB).
This instruction requires a pulse generator. You must activate the pulse generator and select
a signal type in the hardware configuration. Refer to "Configuring a pulse channel for PWM
or PTO" (Page 494) for further information.
You can access the CTRL_PTO instruction in the Task Cards, Extended instructions.
Table 9- 188 CTRL_PTO (Pulse Train Output) instruction
LAD / FBD1
SCL2
"CTRL_PTO_DB"(
REQ:=_bool_in_,
PTO:=_uint_in_,
FREQUENCY:=_udint_in_,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_);
Description
The PTO instruction allows the user to
control the frequency for a square wave
(50% duty cycle) output.
1
When you insert the instruction, STEP 7 displays the "Call Options" dialog for creating the associated DB.
2
In the SCL example, "CTRL_PTO_DB" is the name of the instance DB.
S7-1200 Programmable controller
488
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
Table 9- 189 Data types for the parameters
Parameter and type
Data type
Description
EN
IN
Bool
1 = Instruction enabled
0 = Instruction disabled
REQ
IN
Bool
1 = Set PTO output frequency to value in FREQUENCY input
0 = No change to PTO
PTO
IN
HW_PTO
(Word)
PTO identifier: Hardware ID of the pulse generator:
•
Names of the enabled pulse generators become tags in the "constant" tag table, and are available for use as the PTO parameter.
(Default value = 0)
•
You can find the hardware ID in the Properties of the pulse generator in the Device view. The system constants also list the hardware
IDs of the pulse generators. (Default value = 0)
FREQUENCY
IN
UDInt
Desired frequency (in Hz) of the PTO. This value is applied only when
REQ = 1 (Default value is 0 Hz)
DONE
OUT
Bool
Function completed without error (Default value: 0)
BUSY
OUT
Bool
Function busy (Default value: 0)
ERROR
OUT
Word
Error detected (Default value: 0)
STATUS
OUT
Word
Execution condition code (Default value: 0)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
489
Extended instructions
9.8 Pulse
The CTRL_PTO instruction stores the parameter information in the DB. The data block
parameters are not separately changed by the user, but are controlled by the CTRL_PTO
instruction.
Specify the enabled pulse generator to use, by using its tag name or hardware identifier for
the PTO parameter.
When the EN input is TRUE, the CTRL_PTO instruction starts or stops the identified PTO.
When the EN input is FALSE, the CTRL_PTO instruction does not execute and the PTO
maintains its current state.
When you set the REQ input to TRUE, the FREQUENCY value takes effect. If REQ is
FALSE, the PTO's output frequency cannot be changed, and the PTO continues to output
pulses.
S7-1200 Programmable controller
490
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
Since the CTRL_PTO instruction only starts the PTO, the CTRL_PTO instruction finishes
immediately. As a result, the BUSY output never turns on. The DONE output comes on as
long as no error occurs. If an error is detected, the ERROR parameter is set to TRUE, and
the STATUS parameter contains a condition code.
When the user enables the CTRL_PTO instruction with a given frequency, the S7-1200
outputs a pulse train at that given frequency. The user can change the desired frequency at
any time. When the frequency is changed, the S7-1200 finishes the current pulse prior to
changing frequency to the new desired frequency. For example, if the desired frequency is 1
Hz (which takes 1000ms to complete) and the user changes the frequency to 10 Hz after
500ms, the frequency changes at the end of the 1000ms time period.
①
②
③
The user changes the frequency to 10 Hz after 500 ms.
The 1 Hz pulse must finish before the frequency can change to the new 10 Hz frequency.
1 Hz corresponds to 1000 ms
The pulse generator hardware object has the following restriction: Only one instruction can
use the pulse generator as PTO, and the hardware configuration editor manages the use of
the pulse generator. Other instructions that try to access that PTO return an error: "0x8090"
(Pulse generator with the specified hardware ID is in use).
Note
Digital I/O points assigned to PWM and PTO cannot be forced
The digital I/O points used by the pulse width modulation (PWM) and pulse train output
(PTO) devices are assigned during device configuration. When digital I/O point addresses
are assigned to these devices, the values of the assigned I/O point addresses cannot be
modified by the Watch table force function.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
491
Extended instructions
9.8 Pulse
Table 9- 190 STATUS parameter error code value
Error code (W#16#...)
Description
0
No errors
0x8090
Pulse generator with the specified hardware ID is in use.
0x8091
Frequency out-of-range. The desired frequency exceeds the maximum frequency of the
pulse output selected.
0x80A1
PTO identifier (hardware ID) does not address a valid PTO.
0x80D0
Pulse generator with the specified hardware ID is not activated. Activate the pulse generator in the CPU properties under "Pulse generators (PTO/PWM)".
0x80D1
Pulse generator with the specified hardware ID has no PTO selection. Select PTO in
Hardware Configuration.
9.8.3
Operation of the pulse outputs
Pulse width can be expressed as hundredths of the
cycle time (0 to 100), as thousandths (0 to 1000), as
ten thousandths (0 to 10000), or as S7 analog format.
①
②
Cycle time
The pulse width can vary from 0 (no pulse, always off)
to full scale (no pulse, always on).
Pulse width
Since the PWM output can be varied from 0 to full scale, it provides a digital output that in
many ways is the same as an analog output. For example, the PWM output can be used to
control the speed of a motor from stop to full speed, or it can be used to control position of a
valve from closed to fully opened.
You configure frequency in the hardware configuration. You control pulse width from the user
program.
Four pulse generators are available for controlling high-speed pulse output functions: PWM
and Pulse train output (PTO). PTO is used by the motion control instructions. You can assign
each pulse generator to either PWM or PTO, but not both at the same time.
You can use onboard CPU outputs, or you can use the optional signal board outputs. The
output point numbers are shown in the following table (assuming the default output
configuration). If you have changed the output point numbering, then the output point
numbers will be those you assigned. Note that PWM requires only one output, while PTO
can optionally use two outputs per channel. If an output is not required for a pulse function, it
is available for other uses. Refer to the table below for I/O assignment.
S7-1200 Programmable controller
492
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
The table below shows the default I/O assignments; however, the four pulse generators can
be configured to any CPU built-in or SB digital output. Different output points support
different voltages and speeds, so take that into account when assigning PWM/PTO
locations.
Note
Pulse-train outputs cannot be used by other instructions in the user program.
When you configure the outputs of the CPU or signal board as pulse generators (for use with
the PWM or motion control PTO instructions), the corresponding outputs addresses are
removed from the Q memory and cannot be used for other purposes in your user program. If
your user program writes a value to an output used as a pulse generator, the CPU does not
write that value to the physical output.
Note
PTO direction outputs can be freed for use elsewhere in your program.
Each PTO requires the assignment of two outputs: one as a pulse output and one as a
direction output. You can use just the pulse output and not the direction output. You can then
free the direction output for other purposes in your user program.
Table 9- 191 Default output assignments for the pulse generators3
Description
Pulse
Direction
Built-in I/O
Q0.0
Q0.1
SB I/O
Q4.0
Q4.1
Built-in outputs
Q0.0
-
SB outputs
Q4.0
-
Built-in I/O
Q0.2
Q0.3
SB I/O
Q4.2
Q4.3
Built-in outputs
Q0.2
-
SB outputs
Q4.2
-
Built-in I/O
Q0.41
Q0.51
SB I/O
Q4.0
Q4.1
Built-in outputs
Q0.41
-
SB outputs
Q4.1
-
Built-in I/O
Q0.62
Q0.72
SB I/O
Q4.2
Q4.3
PTO1
PWM1
PTO2
PWM2
PTO3
PWM3
PTO4
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
493
Extended instructions
9.8 Pulse
Description
Pulse
Direction
Built-in outputs
Q0.62
-
SB outputs
Q4.3
-
PWM4
9.8.4
1
The CPU 1211C does not have outputs Q0.4, Q0.5, Q0.6, or Q0.7. Therefore, these outputs cannot be used in the CPU 1211C.
2
The CPU 1212C does not have outputs Q0.6 or Q0.7. Therefore, these outputs cannot be used in
the CPU 1212C.
3
This table applies to the CPU 1211C, CPU 1212C, CPU 1214C, CPU 1215C, and CPU 1217C
PTO/PWM functions.
Configuring a pulse channel for PWM or PTO
To prepare for PWM or PTO operation, first configure a pulse channel in the device
configuration by selecting the CPU, then Pulse Generator (PTO/PWM), and choose
PWM1/PTO1 through PWM4/PTO4. Enable the pulse generator (check box). If a pulse
generator is enabled, a unique default name is assigned to this particular pulse generator.
You can change this name by editing it in the "Name:" edit box, but it must be a unique
name. Names of enabled pulse generators will become tags in the "constant" tag table and
will be available for use as one of the following:
● PWM parameter of the CTRL_PWM instruction
● PTO parameter of the CTRL_PTO instruction
You can also write a comment about this specific pulse generator in the "Comment:" edit
box.
Table 9- 192 CPU output: Maximum frequency (PTO) and minimum cycle time (PWM)
CPU
CPU output channel
PTO maximum frequency
PWM minimum cycle
time
1211C
Qa.0 to Qa.3
100 kHz
10 µs
1212C
Qa.0 to Qa.3
100 kHz
10 µs
Qa.4, Qa.5
20 kHz
50 µs
Qa.0 to Qa.3
100kHz
10 µs
Qa.4 to Qb.1
20 kHz
50 µs
DQa.0 to DQa.3
1 MHz
1 µs
100 kHz
10 µs
1214C and 1215C
1217C
(.0+, .0- to .3+, .3-)
DQa.4 to DQb.1
S7-1200 Programmable controller
494
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
Table 9- 193 SB signal board output: Maximum frequency (PTO) and minimum cycle time (PWM)
SB signal board
SB output channel
PTO maximum frequency
PWM minimum cycle
time
SB 1222, 200 kHz
DQe.0 to DQe.3
200kHz
5 µs
SB 1223, 200 kHz
DQe.0, DQe.1
200kHz
5 µs
SB 1223
DQe.0, DQe.1
20 kHz
50 µs
Note
The minimum cycle time of each of the CPU and Signal Board outputs is given in the tables
above. However, TIA Portal does not alert you when you configure a PWM pulse generator
with a cycle time that exceeds this hardware limitation. Problems can result with your
application, so always ensure that you do not exceed the minimum cycle time of the
hardware.
Parameter assignment
The Parameter assignment section allows the user to configure the parameters of the output
pulse. The following options are available, depending on whether PWM or PTO is selected:
● Signal type: Configure the pulse output as PWM or PTO. For PTO selections, refer to
"Phasing" (Page 658) for further information:
– PWM
– PTO (pulse A and direction B)
– PTO (pulse up A and pulse down B)
– PTO (A/B phase-shifted)
– PTO (A/B phase-shifted - fourfold)
● Time base (only applies to PWM): Select which units of time to use:
– Milliseconds
– Microseconds
● Pulse duration format (only applies to PWM): Assign the resolution of the pulse duration
(width):
– Hundredths (0 to 100)
– Thousandths (0 to 1000)
– Ten-thousandths (0 to 10000)
– S7 analog format (0 to 27648)
● Cycle time (only applies to PWM): Assign the time duration it takes to complete one pulse
(pulse high time plus pulse low time equals cycle time). You can change the cycle time at
runtime by selecting the check box "Allow runtime modification of the cycle time". Refer to
the "I/O addresses" section below for further information. Range is 1 to 16,777,215 units
of time.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
495
Extended instructions
9.8 Pulse
● Initial pulse duration (only applies to PWM): Assign the pulse duration of the first pulse.
You can change this value at runtime using the Q word address configured in I/O
addresses. Range is based upon the Pulse duration format.
● Allow runtime modification of the cycle time (only applies to PWM): Selecting this option
allows your program to modify the cycle time of the PWM signal while the program is
running. Refer to the "I/O addresses" section below for further information.
Note
When setting the pulse duration of a PWM signal, be sure to consider the switching delay of
the output channel as specified in Appendix A. The actual pulse duration measured at the
output may be greater than the selected pulse duration. The increase of the pulse duration is
more pronounced for small pulse duration and higher frequencies. Be sure to verify that the
pulse duration measured at the output matches your requirements.
Determining the Pulse duration value
"Pulse duration" is derived by multiplying the "Initial pulse duration" by the "Cycle time".
When you select a "Time base", "Pulse duration format", "Cycle time", and "Initial pulse
duration", you must keep in mind that the overall "Pulse duration" cannot be a fractional
value. If your resulting "Pulse duration" is a fractional value, you should adjust your "Initial
pulse duration" or change your "Time base" to generate an integer value.
Here are two examples:
● Example 1: If you select the following values:
– Time base = Milliseconds (ms)
– Pulse duration format = Hundredths (0 to 100)
– Cycle time = 3 ms
– Initial pulse duration = 75
The resulting "Pulse duration" = .75 x 3 ms = 2.25 ms
This "Pulse duration" value is fractional and causes an error when you operate the
CTRL_PWM instruction. The "Pulse duration" value must be an integer value.
● Example 2: If you select the following values:
– Time base = Microseconds (µs)
– Pulse duration format = Hundredths (0 to 100)
– Cycle time = 3000 µs
– Initial pulse duration = 75
The resulting "Pulse duration" = .75 x 3000 µs = 2250 µs
This "Pulse duration" value is an integer value, and the CTRL_PWM instruction functions
properly with this value.
S7-1200 Programmable controller
496
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.8 Pulse
Hardware outputs
In the hardware outputs section, select the output channel from the dropdown menu.
Depending on the configuration, there may be one or two outputs to select. If you do assign
an output channel to a pulse generator, the output channel cannot be used by another pulse
generator, HSC, or the process image register.
Note
Pulse generator outputs cannot be used by other instructions in the user program
When you configure the outputs of the CPU or signal board as pulse generators (for use with
the PWM, PTO, or motion control instructions), the corresponding outputs addresses are
removed from the Q memory and cannot be used for other purposes in your program. If your
program writes a value to an output used as a pulse generator, the CPU does not write that
value to the physical output.
I/O addresses
The PWM has two bytes of Q memory designated for "Pulse duration". While the PWM is
running, you can modify the value in the assigned Q memory and change the Pulse duration.
In the I/O Address section, enter the Q word address where you want to store the Pulse
duration value.
The default addresses for the PWM Pulse duration values are as follows:
● PWM1: QW1000
● PWM2: QW1002
● PWM3: QW1004
● PWM4: QW1006
For the PWM, the value at this location controls the duration of the pulse and is initialized to
the "Initial pulse duration:" value (assigned above) each time the CPU transitions from STOP
to RUN mode. You change this Q-word value during runtime to cause a change in the pulse
duration. The range of this value is dependent on the Pulse duration format configured under
Parameter assignment.
You can also allocate an additional four bytes of Q memory for the "Cycle time" of the PWM
signal. Refer to "Operation of the pulse outputs" (Page 492) for a diagram of the PWM
signal. When you select the "Allow runtime modification of the cycle time" check box, the first
two bytes hold the Pulse duration value and the last four bytes hold the Cycle time value.
While the PWM is running, you can modify the value of the double word at the end of the Q
memory that is allocated to that PWM. This changes the Cycle time of the PWM signal. For
example, you enable this option so that the CPU allocates six bytes for PWM1, and you
decide to use QB1008 to QB1013. Once you download the program and start the PWM, you
can modify the Pulse duration using QW1008 and the Cycle time using QD1010.
Each time the CPU transitions from STOP to RUN mode, the CPU initializes the Cycle time
value in Q memory to the "Cycle time" value assigned above in the "Parameter assignment"
section. The units and range of values for the Cycle time value in Q memory are the same as
the configuration in the "Parameter assignment" section.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
497
Extended instructions
9.9 Recipes and Data logs
When you select the "Allow runtime modification of the cycle time" check box, the TIA Portal
automatically selects a new address for the output address. The new output address cannot
be the same as the default address for that pulse generator. The TIA Portal uses the next
available block of six consecutive bytes. If the search does not find an available block of Q
memory before it reaches the end of Q memory, the search starts over at address "0" of Q
memory and continues searching for an available block.
A pulse generator configured for PTO does not use the Q-word address.
9.9
Recipes and Data logs
9.9.1
Recipes
9.9.1.1
Recipe overview
Recipe data storage
● A recipe data block that you create in your project must be stored in CPU load memory.
Internal CPU memory or an external memory "Program" card can be used.
● Another DB that you must create is the active recipe data block. This DB must be in work
memory, where one active recipe record is read or written with your program logic.
Recipe data management
The recipe DB uses an array of product recipe records. Each element of the recipe array
represents a different recipe flavor that is based on a common set of components.
● You create a PLC data type or struct that defines all the components in one recipe record.
This data type template is reused for all recipe records. Product recipes vary according to
the start values that are assigned to the recipe components.
● One of the recipes can be transferred at any time from the recipe DB (all recipes in load
memory) to the active recipe DB (one recipe in work memory) using the READ_DBL
instruction. After a recipe record is moved to work memory, then your program logic can
read the component values and begin a production run. This transfer minimizes the
amount of CPU work memory that is required for recipe data.
● If the active recipe component values are adjusted by an HMI device during a production
run, you can write the modified values back to the recipe DB, using the WRIT_DBL
instruction.
Recipe export (from recipe DB to CSV file)
The complete set of recipe records can be generated as a CSV file using the RecipeExport
instruction. Unused recipe records are also exported.
S7-1200 Programmable controller
498
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Recipe import (from CSV file to recipe DB)
Once a recipe export operation is completed, then you can use the generated CSV file as a
data structure template.
1. Use the file browser page in the CPU web server to download an existing recipe CSV file
from the CPU to a PC
2. Modify the recipe CSV with an ASCII text editor. You can modify the start values
assigned to components, but not the data types or data structure
3. Upload the modified CSV file from PC back to the CPU. However, the old CSV file in CPU
load memory (with the same name) must be deleted or renamed before the CPU Web
server allows the upload operation.
4. After the modified CSV file is uploaded to the CPU, then you can use the RecipeImport
instruction to transfer the new start values from the modified CSV file (in CPU load
memory) to the recipe DB (in CPU load memory).
9.9.1.2
Recipe example
Example recipes
The table below shows how to prepare recipe information for use in a recipe DB. The
example recipe DB stores five records, three of which are used. The fourth and fifth records
are free for later expansions. Each table row represents one record that stores the recipe
name, component data types, and component values.
productname
water
barley
wheat
hops
yeast
waterTmp
Pils
10
9
3
280
39
40
mashTmp mashTime
30
100
QTest
0
Lager
10
9
3
150
33
50
30
120
0
BlackBeer
10
9
3
410
47
60
30
90
1
Not_used
0
0
0
0
0
0
0
0
0
Not_used
0
0
0
0
0
0
0
0
0
Creating a recipe data block
Note
Rules for recipe data blocks
• The recipe DB must contain a single dimension array of either a PLC data type or a
struct. The recipe example shows how to create a recipe DB with a PLC data type.
• In the example, the data type of the component ingredients are all the UINT data type.
The component data types may also be a mix of any data type except for structs. In a
recipe DB array element, a struct in a PLC data type or a struct in a struct is not allowed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
499
Extended instructions
9.9 Recipes and Data logs
First, create a new PLC data type
Add a new PLC data type whose name is the recipe type. In the following image,
"Beer_Recipe" is the new complex PLC data type that stores a sequence of simple data
types. The "Beer_Recipe" PLC data type is a data template that is reused in each recipe DB
record and also in the active recipe DB. Enter the component names and data types that are
common to all the example recipes. The individual component values are added later in the
recipe DB.
Second, create a recipe data block
● Create your recipe DB as a global data block with the DB property "Only store in load
memory" enabled.
● The name of a recipe data block is used as file name of the corresponding CSV file. The
DB name characters you assign must follow the Windows file system naming restrictions.
Characters \ / : * ? " < > | and the space character are not allowed.
● The recipe array assignment is "Products" as Array [1.. 5] of "Beer_Recipe". The array
size 5 is the maximum number of recipe flavors that are possible.
● The values for recipe components are added as DB start values.
In the following image, the "BlackBeer" recipe is expanded to show all the components of a
recipe record.
S7-1200 Programmable controller
500
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Recipe export (from recipe DB to CSV file)
"RecipeExport (Page 502)" execution transfers recipe DB data to a CSV file, as shown in the
following text file.
Recipe_DB.csv
index,productname,water,barley,wheat,hops,yeast,waterTmp,
mashTmp,mashTime,QTest
1,”Pils”,10,9,3,280,39,40,30,100,0
2,”Lager”,10,9,3,150,33,50,30,120,0
3,”BlackBeer”,10,9,3,410,47,60,30,90,1
4 ”Not_used”,0,0,0,0,0,0,0,0,0
5 ”Not_used”,0,0,0,0,0,0,0,0,0
Recipe import (from CSV file to recipe DB)
1. Use the file browser page in the CPU web server to download an existing recipe CSV file
from CPU load memory to a PC
2. Modify the recipe CSV with an ASCII text editor. You can modify the start values
assigned to components, but not the data types or data structure
3. Upload the modified CSV file from PC back to the CPU. However, the old CSV file in CPU
load memory (with the same name) must be deleted or renamed before the CPU Web
server allows the upload operation.
4. After the modified CSV file is uploaded to the CPU, then you can use the RecipeImport
instruction to transfer the new start values from the modified CSV file (in CPU load
memory) to the recipe DB (in CPU load memory).
CSV files must exactly match the corresponding recipe DB structure
● The values in the CSV file can be changed, but changing the structure is not allowed. The
RecipeImport instruction requires that the exact number of records and components
matches the destination recipe DB structure. Otherwise, RecipeImport execution fails. For
example, if 10 recipes are defined in the recipe DB but only 6 are in use, then line 7 to 10
in the CSV file are also transferred to the DB. You must coordinate whether this data is
valid or not. For example, you can assign a variable “Not_used” for the product name in
unused recipe records.
● If you add data records to the text file and import the modified file, make sure the recipe
DB array limit you assign has enough elements for all the recipe records.
● An index number is automatically generated during export to the CSV file. If you create
additional data records, add consecutive index numbers accordingly.
● RecipeImport execution checks the CSV file data for correct structure and whether the
values fit in the data types assigned in the associated recipe DB. For example, a Bool
data type cannot store an integer value and the RecipeImport execution fails.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
501
Extended instructions
9.9 Recipes and Data logs
Display CSV recipe data in Excel
The CSV file can be opened in Excel to make reading and editing easier. If the commas are
not recognized as decimal separators, use the Excel import function to output the data in
structured form
9.9.1.3
Program instructions that transfer recipe data
RecipeExport (Recipe export)
Table 9- 194 RecipeExport instruction
LAD/FBD
SCL
"RecipeExport_DB"(
req:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
Recipe_DB:=_variant_inout_);
Description
The "RecipeExport" instruction exports all
recipe records from a recipe data block to
the CSV file format. The CSV file contains
product names, component names, and start
values. The CSV file is stored in internal load
memory or external load memory, if an optional external "program" memory card is
installed.
The export operation is triggered by the
"REQ" parameter. The BUSY parameter is
set to "1" during export processing. After the
execution of RecipeExport stops, BUSY is
reset to "0" and the completion of the operation is indicated with "1" at the DONE parameter. If an error occurs during execution,
then parameters ERROR and STATUS indicate the result.
A recipe DB must be created before a recipe export is possible. The name of a recipe data
block is used as the file name of the new CSV file. If a CSV file with an identical name
already exists, then it is overwritten during the export operation.
You can use the File Browser page (Page 1037) of the CPU's built-in Web server to access
the recipe CSV file. The file is put in the recipe folder in the root directory of CPU load
memory.
S7-1200 Programmable controller
502
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Table 9- 195 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
Control parameter REQUEST: Activates the export on a positive
edge.
RECIPE_DB
In/Out
Variant
Pointer to the recipe data block. Refer to the "Recipe DB example
(Page 499)" for details. The DB name characters must follow the
Windows file system naming restrictions. Characters \ / : * ? " < > |
and the space character are not allowed.
DONE
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was completed with no error. (Default value: False)
BUSY
OUT
Bool
RecipeExport execution
ERROR
STATUS
OUT
OUT
Bool
Word
•
0: No operation in progress
•
1: Operation on progress
The ERROR bit is TRUE for one scan, after the last request was
terminated with an error. The error code value at the STATUS parameter is valid only during the single scan where ERROR = TRUE.
•
0: No warning or error
•
1: An error has occurred. The STATUS parameter provides information on the type of error.
Execution condition code
Table 9- 196 Values of ERROR and STATUS
ERROR
STATUS
(W#16#....)
Description
0
0000
No error
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All instance memory is in use.
1
8090
File name contains invalid characters
1
8091
The data structure referenced with RECIPE_DB cannot be processed.
1
8092
Data structure specified in RECIPE_DB exceeds 5000 bytes
1
80B3
Not enough space in on MC or in internal load memory
1
80B4
MC is write protected
1
80B6
Recipe DB attribute "Only store in load memory" is not enabled.
1
80C0
CSV file is temporarily locked
1
80C1
DB is temporarily locked
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
503
Extended instructions
9.9 Recipes and Data logs
RecipeImport (Recipe import)
Table 9- 197 RecipeImport instruction
LAD/FBD
SCL
"RecipeImport_DB"(
req:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
Recipe_DB:=_variant_inout_);
Description
The "RecipeImport" instruction imports recipe data from a CSV file, in
CPU load memory, to a recipe data
block referenced by the RECIPE_DB
parameter. Start values in the recipe
data block are overwritten by the
import process. The import operation
is triggered by the "REQ" parameter.
The BUSY parameter is set to "1"
during import processing. After the
execution of RecipeImport stops,
BUSY is reset to "0" and the completion of the operation is indicated with
"1" at the DONE parameter. If an
error occurs during execution, then
parameters ERROR and STATUS
indicate the result.
Table 9- 198 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
Control parameter REQUEST: Activates the import on a positive edge.
RECIPE_DB
In/Out
Variant
Pointer to the recipe data block. Refer to "Recipe DB example
(Page 499)" for details. The DB name characters must follow the Windows file system naming restrictions. Characters \ / : * ? " < > | and the
space character are not allowed.
DONE
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was completed with no error. (Default value: False)
BUSY
OUT
Bool
•
0 - No operation in progress
•
1 - Operation on progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last request was terminated with an error. The error code value at the STATUS parameter
is valid only during the single scan where ERROR = TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
S7-1200 Programmable controller
504
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
A recipe DB that contains a structure which is consistent with the CSV file data structure
must exist, before a recipe import operation is possible.
CSV file rules:
● The CSV file must be located in the root directory "Recipes" folder of internal load
memory or external load memory, if an optional external "program" memory card is
installed.
● The name of the CSV file must match the name of the data block at the RECIPE_DB
parameter.
● The first line (header) of the CSV file contains the name of the recipe components. The
first line is ignored during import. The names of the recipe components in the CSV file
and the data block are not reconciled during the import process.
● In each case the first value in each line of the CSV file is the index number of the recipe.
The individual recipes are imported in the order of the index. For this, the index in the
CSV file has to be in ascending order and may contain no gaps (if this is not the case, the
error message 80B0 is output at the STATUS parameter).
● The CSV file may not contain more recipe data records than provided for in the recipe
data block. The maximum number of data records is indicated by the array limits in the
data block.
Table 9- 199 Values of ERROR and STATUS
ERROR
STATUS
(W#16#....)
Description
0
0000
No error
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All instance memory is in use.
1
8090
The file name contains invalid characters.
1
8092
No matching CSV file found for the import. Possible cause: The name of the CSV file
does not match the name of the recipe DB.
1
80C0
CSV file is temporarily locked.
1
80C1
Data block is temporarily locked.
1
80B0
Numbering in the index of the CSV file is not continuous, not ascending or exceeds the
maximum number (array limit) in the data block.
1
80B1
Structure of the recipe data block and the CSV file do not match: The CSV file contains
too many fields.
1
80B2
Structure of the recipe data block and the CSV file do not match: The CSV file contains
too few fields.
1
80B6
Recipe DB attribute "Only store in load memory" is not enabled.
1
80D0 +n
Structure of the recipe data block and the CSV file do not match: Data type in field n
does not match (n<=46).
1
80FF
Structure of the recipe data block and the CSV file do not match: Data type in field n
does not match (n>46).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
505
Extended instructions
9.9 Recipes and Data logs
9.9.1.4
Recipe example program
Prerequisites for the recipe example program
The prerequisites for the recipe example program are as follows:
● A recipe DB that stores all recipe records. The recipe DB is stored in load memory.
● An active recipe DB that stores a copy of one recipe in work memory.
Refer to the "Recipe DB example (Page 499)" for details about the recipe DB and the
corresponding CSV file.
Create the active recipe DB
On the "Add new block" window:
● Select the "Data block" button on the "Add new block" window
● On the "Type" drop-down menu, select the "Beer_recipe" PLC data type that you created
previously.
Start values are not required. The DB data values are set when one recipe is transferred
from the recipe DB to the active recipe DB. In the example, the active recipe DB is the
destination for READ_DBL data and provides source data for WRITE_DBL. The following
image shows the Active_Recipe DB.
Instance DBs
The instance DBs used by instructions RecipeExport ("RecipeExport_DB") and RecipeImport
("RecipeImport_DB") are created automatically when you place the instructions in your
program. The instance DBs are used to control instruction execution and are not referenced
in the program logic.
S7-1200 Programmable controller
506
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Example recipe program
Network 1 A rising edge on REQ starts the export process. A CSV file is generated from the
recipe DB data and placed in the CPU memory recipes folder.
Network 2 Capture the STATUS output from RecipeExport execution, because it is only valid
for one scan.
Network 3 A rising edge on REQ starts the import process. The existing recipe DB is loaded
with all recipe data read from the corresponding CSV file that is located in the CPU memory
recipes folder.
Network 4 Capture the STATUS output from RecipeImport execution, because it is only valid
for one scan.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
507
Extended instructions
9.9 Recipes and Data logs
Network 5 READ_DBL copies the start values from one recipe "Recipe_DB". Products[1] (in
CPU load memory) to the Active_Recipe DB current values (in CPU work memory). After
READ_DBL execution, your program logic can access the recipe component values by
addressing locations in the Active_Recipe DB. For example, the symbolic addresses (
"Active_Recipe".productname) and ("Active_Recipe.water) provide your program logic with
the current recipe name and quantity of water.
Network 6 During run time, An HMI device could modify a component value stored in the
Active_Recipe DB. Improved recipe data can be stored by executing WRIT_DBL. In the
example, all Recipe_DB start values for the single recipe "Recipe_DB". Products[1] are
overwritten by the current values from the "Active_Recipe" DB.
S7-1200 Programmable controller
508
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
9.9.2
Data logs
Your control program can use the Data log instructions to store run-time data values in
persistent log files. The CPU stores data log files in flash memory (CPU or memory card) in
standard CSV (Comma Separated Value) format. The CPU organizes the data records as a
circular log file of a pre-determined size.
You use the Data log instructions in your program to create, open, write a record to, and
close the log files. You decide which program values to log by creating a data buffer that
defines a single log record. The CPU uses your data buffer as temporary storage for a new
log record. Your control program moves new current values into the buffer during runtime.
When the program has updated all of the current data values, it can then execute the
DataLogWrite instruction to transfer data from the buffer to a data log record.
You can open, edit, save, rename, and delete data log files from the File Browser page of
the Web Server. You must have read privileges to view the file browser and you must have
modify privileges to edit, delete, or rename data log files.
9.9.2.1
Data log record structure
The DATA and HEADER parameters of the DataLogCreate instruction assign the data type
and the column header description of all data elements in a log record.
DATA parameter for the DataLogCreate instruction
The DATA parameter points to memory used as a temporary buffer for a new log record and
must be assigned to an M or DB location.
You can assign an entire DB (derived from a PLC data type that you assign when the DB is
created) or part of a DB (the specified DB element can be any data type, data type structure,
PLC data type, or data array).
Structure data types are limited to a single nesting level. The total number of data elements
declared should correspond to the number of columns specified in the header parameter.
The maximum number of data elements you can assign is 253 (with a timestamp) or 255
(without a timestamp). This restriction keeps your record inside the 256 column limit of an
Excel sheet.
The DATA parameter can assign either retentive or non-retentive data elements in a
"Standard" (compatible with S7-300/400) or "Optimized" DB type.
In order to write a Data log record you must first load the temporary DATA record with new
process values and then execute the DataLogWrite instruction that saves new record values
in the Datalog file.
HEADER parameter for the DataLogCreate instruction
The HEADER parameter points to column header names for the top row of the data matrix
encoded in the CSV file. HEADER data must be located in DB or M memory and the
characters must follow standard CSV format rules with commas separating each column
name. The data type may be a string, byte array, or character array. Character/byte arrays
allow increased size, where strings are limited to a maximum of 255 bytes. The HEADER
parameter is optional. If the HEADER is not assigned, then no header row is created in the
Data log file.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
509
Extended instructions
9.9 Recipes and Data logs
9.9.2.2
Program instructions that control data logs
DataLogCreate (Create data log)
Table 9- 200 DataLogCreate instruction
LAD/FBD
1
SCL
"DataLogCreate_DB"(
req:=_bool_in_,
records:=_udint_in_,
format:=_uint_in_,
timestamp:=_uint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
name:=_string_inout_,
ID:=_dword_inout_,
header:=_variant_inout_,
data:=_variant_inout_);
Description
Creates and initializes a data log file. The CPU
creates the file in the \DataLogs folder, using the
name in the NAME parameter, and implicitly
opens the file for write operations. You can use
the Data log instructions in your program to store
runtime process data in the flash memory of the
CPU or on the memory card.
STEP 7 automatically creates the associated
instance DB when you insert the instruction.
In the SCL example, "DataLogCreate_DB" is the name of the instance DB.
Table 9- 201 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
A low to high (positive edge) signal starts the operation.
(Default value: False)
RECORDS
IN
UDint
The maximum number of data records the circular data
log can contain before overwriting the oldest entry:
The header record is not included. Sufficient available
PLC load memory must exist in order to successfully
create the data log. (Default value - 1)
FORMAT
TIMESTAMP
IN
IN
UInt
UInt
Data log format:
•
0 - Internal format (not supported)
•
1 - Comma separated values "csv-eng" (Default value)
Data time stamp format: Column headers for date and
time fields are not required. The time stamp uses the
system time (Coordinated Universal Time - UTC) and not
the local time.
•
0 - No time stamp
•
1 - Date and time stamp (Default value)
S7-1200 Programmable controller
510
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Parameter and type
NAME
IN
Data type
Description
Variant
Data log name: You provide the name. This variant only
supports a String data type and can only be located in
local, DB, or M memory. (Default value: ' ')
The string reference is also used as the name of the data
log file. The name characters must follow the Windows
file system naming restrictions. Characters \ / : * ? " < > |
and the space character are not allowed.
ID
In/Out
DWord
HEADER
In/Out
Variant
Data log numeric identifier: You store this generated
value for use with other Data log instructions. The ID
parameter is only used as an output with the DataLogCreate instruction. (Default value: 0)
Symbolic name access for this parameter is not allowed.
Pointer to data log column header names for the top row
of the data matrix encoded in the CSV file. (Default value: null).
HEADER data must be located in DB or M memory.
The characters must follow standard CSV format rules
with commas separating each column name. The data
type may be a string, byte array, or character array.
Character/byte arrays allow increased size, where
strings are limited to a maximum of 255 bytes.
The HEADER parameter is optional. If the HEADER is
not parameterized, then no header row is created in the
Data log file.
DATA
In/Out
Variant
Pointer to the record data structure, user defined type
(UDT), or array. Record data must be located in DB or M
memory.
The DATA parameter specifies the individual data elements (columns) of a data log record and their data type.
Structure data types are limited to a single nesting level.
The number of data elements declared should correspond to the number of columns specified in the header
parameter. The maximum number of data elements you
can assign is 253 (with a timestamp) or 255 (without a
timestamp). This restriction keeps your record inside the
256 column limit of an Excel sheet.
DONE
OUT
Bool
BUSY
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was completed with no error. (Default value: False)
•
0 - No operation in progress
•
1 - Operation on progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last
request was terminated with an error. The error code
value at the STATUS parameter is valid only during the
single scan where ERROR = TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
511
Extended instructions
9.9 Recipes and Data logs
The CPU creates a data log file with a pre-determined fixed sized based on the RECORDS
and DATA parameters and organizes the data records as a circular log file. The
DataLogWrite instruction appends new records to the data log file until it stores the
maximum number of records that is specified by the RECORDS parameter. The next record
written will overwrite the oldest record. Another DataLogWrite operation will overwrite the
next oldest data record and so on.
Memory resource usage:
● The data logs consume only load memory.
● The size of all data logs combined is limited by the available resources of load memory.
Only eight data logs can be open at one time. You can manage your data logs from the
File Browser (Page 1037) standard Web page. See the description of this standard Web
page for guidelines on how many data logs to maintain at a time.
● The maximum possible number for the RECORDS parameter is the limit for an UDint
number (4,294,967,295). The actual limit for the RECORD parameter depends on the
size of a single record, the size of other data logs, and the available resources of load
memory. In addition, Excel limits the number of rows allowed in an Excel sheet.
Note
Data log creation execution must be complete before starting a data log write operation
• DataLogCreate and DataLogNewFile log file creation operations extend over many
program scan cycles. The actual time required for the log file creation depends on the
record structure and number of records. Your program logic must monitor and catch the
DONE bit's transition to the TRUE state that signals the completion of a log file creation. If
the user program executes a DataLogWrite instruction before a data log creation
operation is complete, then the write operation will fail to write a new data log record as
expected.
• In certain situations when a very fast program scan is running, data log creation can take
an extended time. If the long creation time is too slow, you should ensure that the
checkbox for the Enable minimum cycle time for cyclic OBs is active, and the minimum
cycle time is set to one ms or greater. Refer to Configuring the cycle time and
communication load (Page 109) for more information.
Note
The DataLogNewFile instruction copies an existing data log's record structure
If you want to prevent overwriting any data records, then you can use the DataLogNewFile
instruction to create a new data log based on the current data log, after the current data log
has stored the maximum number of records. New data records are stored in the new data
log file. The old data log file and record data remain stored in flash memory.
S7-1200 Programmable controller
512
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Table 9- 202 Values of ERROR and STATUS
ERROR
STATUS
(W#16#....)
Description
0
0000
No error
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All internal instance memory is in use.
1
807F
Internal error
1
8090
Invalid file name
1
8091
Name parameter is not a String reference.
1
8093
A data log already exists with that name. Use a different name, make sure the existing
data log's .csv file is not open, and then use the File Browser (Page 1037) page of the
Web Server to delete the existing data log.
1
8097
Requested file length exceeds file system maximum.
1
80B2
Out of resource IDs
Note: Delete some existing data logs or decrease the number of columns in the data
record structure to avoid this error.
1
80B3
Insufficient load memory available.
1
80B4
MC (memory card) is write-protected.
1
80C0
Archive file is locked
1
80C1
Too many open files: No more than eight opened data log files are allowed.
1
8253
Invalid record count
1
8353
Invalid format selection
1
8453
Invalid timestamp selection
1
8B24
Invalid HEADER area assignment: For example, pointing to local memory
1
8B51
Invalid HEADER parameter data type
1
8B52
Too many HEADER parameter data elements
1
8C24
Invalid DATA area assignment: For example, pointing to local memory
1
8C51
Invalid DATA parameter data type
1
8C52
Too many DATA parameter data elements
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
513
Extended instructions
9.9 Recipes and Data logs
DataLogOpen (Open data log)
Table 9- 203 DataLogOpen instruction
LAD / FBD
SCL
"DataLogOpen_DB"(
req:=_bool_in_,
mode:=_uint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
name:=_string_inout_,
ID:=_dword_inout_);
Description
Opens a pre-existing data log file. You must open a data log before
you can write (Page 516) new records to the log. You can open and
close data logs individually. A maximum of eight data logs can be
open at the same time.
STEP 7 automatically creates the associated instance DB when
you insert the instruction.
In the SCL example, "DataLogOpen_DB" is the name of the instance DB.
2
Table 9- 204 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
A low to high (positive edge) signal starts the operation. (Default
value: False)
MODE
IN
UInt
Operation mode:
•
0 - Append to existing data (Default value)
•
1 - Clear all existing records
NAME
IN
Variant
Name of an existing data log: This variant only supports a String
data type and can only be located in local, DB, or M memory. (Default value: ' ')
ID
In/Out
DWord
Numeric identifier of a data log. (Default value: 0)
Note: Symbolic name access for this parameter is not allowed.
DONE
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was
completed with no error. (Default value: False)
BUSY
OUT
Bool
•
0 - No operation in progress
•
1 - Operation in progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last request was
terminated with an error. The error code value at the STATUS
parameter is valid only during the single scan where ERROR =
TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
S7-1200 Programmable controller
514
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
You can provide either the NAME or an ID (ID parameter as an input) of a pre-existing data
log. If you provide both parameters and a valid ID does correspond to the NAME data log,
then the ID is used, and the NAME ignored.
The NAME must be the name of a data log created by the DataLogCreate instruction. If only
the NAME is provided and the NAME specifies a valid data log, then the corresponding ID
will be returned (ID parameter as an output).
Note
General usage of data log files
• Data log files are automatically opened after the DataLogCreate and DataLogNewFile
operations.
• Data log files are automatically closed after a PLC run to stop transition or a PLC power
cycle.
• A Data log file must be open before a new DataLogWrite operation is possible.
• A maximum of eight data log files may be open at one time. More than eight data log files
may exist, but some of them must be closed so no more than eight are open.
Table 9- 205 Values of ERROR and STATUS
ERROR
STATUS (W#16#)
Description
0
0000
No error
0
0002
Warning: Data log file already open by this application program
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All internal instance memory is in use.
1
8090
Data log definition is inconsistent with existing data log file.
1
8091
Name parameter is not a String reference.
1
8092
Data log does not exist.
1
80C0
Data log file is locked.
1
80C1
Too many open files: No more than eight opened data log files are allowed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
515
Extended instructions
9.9 Recipes and Data logs
DataLogWrite (Write data log)
Table 9- 206 DataLogWrite instruction
LAD / FBD
SCL
"DataLogWrite_DB"(
req:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
ID:=_dword_inout_);
Description
Writes a data record into the specified data log. The pre-existing target
data log must be open (Page 514) before you can write to it with a DataLogWrite instruction.
STEP 7 automatically creates the associated instance DB when you
insert the instruction.
In the SCL example, "DataLogWrite_DB" is the name of the instance DB.
2
Table 9- 207 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
A low to high (positive edge) signal starts the operation. (Default value:
False)
ID
In/Out
DWord
Numeric data log identifier. Only used as an input for the DataLogWrite
instruction. (Default value: 0)
Note: Symbolic name access for this parameter is not allowed.
DONE
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was completed with no error.
BUSY
OUT
Bool
•
0 - No operation in progress
•
1 - Operation on progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last request was terminated with an error. The error code value at the STATUS parameter is
valid only during the single scan where ERROR = TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
The DATA parameter of a DataLogCreate instruction defines the memory address and data
structure of the record buffer. The control program must load the record buffer with current
runtime process values and then execute the DataLogWrite instruction to move new record
data from the buffer to the data log.
The ID parameter identifies a data log and data record configuration. The DataLogCreate
instruction generates the ID number.
If there are empty records in the circular data log file, then the DataLogWrite instruction
writes the next available empty record. If all records are full, then the DataLogWrite
instruction overwrites the oldest record.
S7-1200 Programmable controller
516
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
NOTICE
Data log creation operations must be complete, before starting a data log write operation
DataLogCreate and DataLogNewFile log file creation operations extend over many
program scan cycles. The actual time required for the log file creation depends on the
record structure and number of records. Your program logic must monitor and catch the
DONE bit's transition to the TRUE state that signals the completion of a log file creation. If a
DataLogWrite instruction executes before a data log creation operation is complete, then
the write operation does not write a new data log record.
Note
Effect of data logs on internal CPU memory
Each data log write consumes at a minimum 2 KB of memory. If your program writes small
amounts of data frequently, it is consuming at least 2 KB of memory on each write. A better
implementation would be to accumulate the small data items in a data block (DB), and to
write the data block to the data log at less frequent intervals.
If your program writes many data log entries at a high frequency, consider using a
replaceable SD memory card.
NOTICE
Potential for data log data loss during a CPU power failure
If there is a power failure during an incomplete DataLogWrite operation, then the data
record being transferred to the data log could be lost.
Table 9- 208 Values of ERROR and STATUS
ERROR
STATUS (W#16#)
Description
0
0000
No error
0
0001
Indicates that the data log is full: Each data log is created with a specified maximum number of records. The last record of the maximum number has been
written. The next write operation will overwrite the oldest record.
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All internal instance memory is in use.
1
8092
Data log does not exist.
1
80B0
Data log file is not open (for explicit open mode only).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
517
Extended instructions
9.9 Recipes and Data logs
DataLogClear (Empty data log)
Description
Table 9- 209 DataLogClear instruction
LAD / FBD
SCL
"DataLogClear_DB"(
REQ:=_bool_in_,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_,
Description
The "DataLogClear" instruction deletes all data
records in an existing data log. The instruction
does not delete the optional header of the CSV file
(see the description of the HEADER parameter of
the instruction "DataLogCreate (Page 510)").
You use the ID parameter to select the data log
whose data records are to be deleted.
ID:=_dword_inout_);
"DataLogClear_DB" is the name of the instance DB.
Requirement
Before you can delete data records, the data log must be open (see "DataLogOpen
(Page 514) instruction").
Parameters
The following table shows the parameters of the "DataLogClear" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, L, D, T, C or
constant
Execution of the instruction upon a rising
edge.
(T and C are only
available in LAD and
FBD with S7-1500)
ID
InOut
DWORD
I, Q, M, D, L
Numeric data log identifier
DONE
Output
BOOL
I, Q, M, D, L
Instruction was executed successfully.
BUSY
Output
BOOL
I, Q, M, D, L
Execution of the instruction not yet complete.
ERROR
Output
BOOL
I, Q, M, D, L
•
0: No error.
1: An error occurred during execution of
the instruction.
Detailed information is output at the STATUS
parameter.
•
STATUS
Output
WORD
I, Q, M, D, L
Status parameter
The parameter is only set for the duration of
one call. To display the status, you should
therefore copy the STATUS parameter to a
free data area.
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
518
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Parameter STATUS
Error code*
(W#16#...)
Explanation
0000
No error.
7000
No job processing active.
7001
Start of job processing. Parameter BUSY = 1, DONE = 0
7002
Intermediate call (REQ irrelevant): Instruction already active; BUSY has the value "1".
8080
The data log file selected with the ID parameter cannot be processed with the "DataLogClear" instruction.
8092
Data log does not exist.
80A2
Write error signaled back by the file system.
80B0
Data log is not open.
80B4
The memory card is write-protected.
* The error codes can be displayed as integer or hexadecimal values in the program editor. For information on switching
the display formats, refer to "See also".
DataLogClose (Close data log)
Table 9- 210 DataLogClose instruction
LAD / FBD
2
SCL
"DataLogClose_DB"(
req:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
ID:=_dword_inout_);
Description
Closes an open data log file. DataLogWrite operations to
a closed data log result in an error. No write operations
are allowed to this data log until another DataLogOpen
operation is performed.
A transition to STOP mode will close all open data log
files.
STEP 7 automatically creates the associated instance
DB when you insert the instruction.
In the SCL example, "DataLogClose_DB" is the name of the instance DB.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
519
Extended instructions
9.9 Recipes and Data logs
Table 9- 211 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
A low to high (positive edge) signal starts the operation. (Default value: False)
ID
In/Out
DWord
Numeric identifier of a data log. Only used as an input for the DataLogClose
instruction. (Default value: 0)
Note: Symbolic name access for this parameter is not allowed.
DONE
OUT
Bool
The DONE bit is TRUE for one scan after the last request was completed with
no error.
BUSY
OUT
Bool
•
0 - No operation in progress
•
1- Operation in progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last request was terminated
with an error. The error code value at the STATUS parameter is valid only
during the single scan where ERROR = TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
Table 9- 212 Values of ERROR and STATUS
ERROR
STATUS (W#16#)
Description
0
0000
No error
0
0001
Data log not open
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8092
Data log does not exist.
DataLogDelete (Delete data log)
Table 9- 213 DataLogDelete instruction
LAD / FBD
SCL
"DataLogDelete_DB"(
REQ:=_bool_in_,
NAME:=_variant_in_,
DelFile:=_bool_in_,
DONE=>_bool_out_,
BUSY=>_bool_out_,
ERROR=>_bool_out_,
STATUS=>_word_out_,
ID:=_dword_inout_);
Description
You use the "DataLogDelete" instruction to delete
a data log file. The data log and the data records
it contains can only be deleted if it was created
with the "DataLogCreate" or "DataLogNewFile"
instruction.
"DataLogDelete_DB" is the name of the instance DB.
S7-1200 Programmable controller
520
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Parameters
The following table shows the parameters of the "DataLogDelete" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, L, D, T, C or
constant
Execution of the instruction upon a rising
edge.
(T and C are only
available in LAD and
FBD with S7-1500)
NAME
Input
VARIANT
L, D
File name of the data log
DELFILE
Input
BOOL
I, Q, M, D, L or constant
•
0: Data log is retained.
•
1: Data log is deleted.
ID
InOut
DWORD
I, Q, M, D, L
Numeric data log identifier
DONE
Output
BOOL
I, Q, M, D, L
Instruction executed successfully.
BUSY
Output
BOOL
I, Q, M, D, L
Deletion of the data log is not yet complete.
ERROR
Output
BOOL
I, Q, M, D, L
•
0: No error.
1: An error occurred during execution of
the instruction.
Detailed information is output at the STATUS
parameter.
•
STATUS
Output
WORD
I, Q, M, D, L
Status parameter
The parameter is only set for the duration of
one call. To display the status, you should
therefore copy the STATUS parameter to a
free data area.
You can find additional information on valid data types under "Data types (Page 125)".
Parameters NAME and ID
Select the data log to be deleted using the NAME and ID parameters. The ID parameter is
evaluated first. If there is a data log with the relevant ID, the NAME parameter will not be
evaluated. If the value "0" is used at the ID parameter, a value with the data type STRING
must be used at the NAME parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
521
Extended instructions
9.9 Recipes and Data logs
Parameter RET_VAL
Error code*
(W#16#...)
Explanation
0
No error.
7000
No job processing active.
7001
Start of job processing. Parameter BUSY = 1, DONE = 0
7002
Intermediate call (REQ irrelevant): Instruction already active; BUSY has the value "1".
8091
A data type other than STRING is being used at the NAME parameter.
8092
Data log does not exist.
80A2
Write error signaled back by the file system.
80B4
The memory card is write-protected.
* The error codes can be displayed as integer or hexadecimal values in the program editor. For information on switching
the display formats, refer to "See also".
DataLogNewFile (Data log in new file)
Table 9- 214 DataLogNewFile instruction
LAD / FBD
2
SCL
"DataLogNewFile_DB"(
req:=_bool_in_,
records=:_udint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
name=:_DataLog_out_,
ID:=_dword_inout_);
Description
Allows your program to create a new data
log file based upon an existing data log file.
STEP 7 automatically creates the associated
instance DB when you insert the instruction.
In the SCL example, "DataLogNewFile_DB" is the name of the instance DB.
S7-1200 Programmable controller
522
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Table 9- 215 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
A low to high (positive edge) signal starts the operation. (Default value:
False)
RECORDS
IN
UDInt
The maximum number of data records the circular data log can contain
before overwriting the oldest entry. (Default value: 1)
The header record is not included. Sufficient available CPU load memory
must exist in order to successfully create the data log.
NAME
IN
Variant
Data log name: You provide the name. This variant only supports a String
data type and can only be located in local, DB, or M memory. (Default value:
' ')
The string reference is also used as the name of the data log file. The name
characters must follow the Windows file system naming restrictions. Characters \ / : * ? " < > | and the space character are not allowed.)
ID
In/Out
DWord
Numeric data log identifier(Default value: 0):
•
At execution, the ID input identifies a valid data log. The new data log
configuration is copied from this data log.
After execution, the ID parameter becomes an output that returns the ID
of the newly created data log file.
Note: Symbolic name access for this parameter is not allowed.
•
DONE
OUT
Bool
The DONE bit is TRUE for one scan, after the last request was completed
with no error.
BUSY
OUT
Bool
•
0 - No operation in progress
•
1 - Operation in progress
ERROR
OUT
Bool
The ERROR bit is TRUE for one scan, after the last request was terminated
with an error. The error code value at the STATUS parameter is valid only
during the single scan where ERROR = TRUE.
STATUS
OUT
Word
Execution condition code (Default value: 0)
You can execute the DataLogNewFile instruction when a data log becomes full or is deemed
completed and you do not want to lose any data that is stored in the data log. A new empty
data log file can be created based on the structure of the full Data log file. The header record
will be duplicated from the original data log with the original data log properties (DATA record
buffer, data format, and timestamp settings). The original Data log file is implicitly closed and
the new Data log file is implicitly opened.
DataLogWrite parameter trigger: Your program must monitor the ERROR and STATUS
parameters of each DataLogWrite operation. When the final record is written and a data log
is full, the DataLogWrite ERROR bit = 1 and the DataLogWrite STATUS word = 1. These
ERROR and STATUS values are valid for one scan only, so your monitoring logic must use
ERROR = 1 as a time gate to capture the STATUS value and then test for STATUS = 1 (the
data log is full).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
523
Extended instructions
9.9 Recipes and Data logs
DataLogNewFile operation: When your program logic gets the data log is full signal, this
state is used to activate a DataLogNewFile operation. You must execute DataLogNewFile
with the ID of an existing (usually full) and open data log, but a new unique NAME
parameter. After the DataLogNewFile operation is done, a new data log ID value is returned
(as an output parameter) that corresponds to the new data log name. The new data log file is
implicitly opened and is ready to store new records. New DataLogWrite operations that are
directed to the new data log file, must use the ID value returned by the DataLogNewFile
operation.
NOTICE
Data log creation operations must be complete, before starting a data log write operation
DataLogCreate and DataLogNewFile log file creation operations extend over many
program scan cycles. The actual time required for the log file creation depends on the
record structure and number of records. Your program logic must monitor and catch the
DONE bit's transition to the TRUE state that signals the completion of a log file creation. If a
DataLogWrite instruction is executed before a data log creation operation is complete, then
the write operation will fail to write a new data log record as expected.
Table 9- 216 Values of ERROR and STATUS
ERROR
STATUS (W#16#)
Description
0
0000
No error
0
7000
Call with no REQ edge: BUSY = 0, DONE = 0
0
7001
First call with REQ edge (working): BUSY = 1, DONE = 0
0
7002
Nth call (working): BUSY = 1, DONE = 0
1
8070
All internal instance memory is in use.
1
8090
Invalid file name
1
8091
Name parameter is not a String reference.
1
8092
Data log does not exist.
1
8093
Data log already exists.
1
8097
Requested file length exceeds file system maximum.
1
80B2
Out of resource IDs
Note: Delete some existing data logs to create resources for a new data log.
1
80B3
Insufficient load memory available.
1
80B4
MC is write-protected.
1
80C1
Too many open files.
S7-1200 Programmable controller
524
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
9.9.2.3
Working with data logs
The data log files are stored as comma separated value format (*.csv) in persistent flash
memory. You can view the data logs by using the PLC Web server feature or by removing
the PLC memory card and inserting it in a standard PC card reader.
Viewing data logs with the PLC Web server feature
If the PLC PROFINET port and a PC are connected to a network, then you can use a PC
web browser like Microsoft Internet Explorer or Mozilla Firefox to access the built-in PLC
Web server. The PLC may be in run mode or stop mode when you operate the PLC Web
server. If the PLC is in run mode, then your control program continues to execute while the
PLC Web server is transferring log data through the network.
Web server access:
1. Enable the Web server in the Device Configuration for the target CPU (Page 1003).
2. Connect your PC to the PLC through the PROFINET network (Page 1007).
3. Access the CPU through the built-in Web server (Page 1011).
4. Download, edit, and delete data log files with the "File Browser" standard Web page
(Page 1037).
5. Open the .csv file with a spreadsheet application like Microsoft Excel.
Note
Data log management
Keep no more than 1000 data logs in a file system. Exceeding this number can prevent the
Web server from having enough CPU resources to display the data logs.
If you find that the File Browser Web page is not able to display the data logs, then you must
place the CPU in STOP mode in order to display and delete data logs.
Manage your data logs to ensure that you only keep the number that you need to maintain,
and do not exceed 1000 data logs.
Viewing data logs on a PLC memory card
If the S7-1200 CPU has a "Program" type S7-1200 memory card inserted, then you can
remove the memory card and insert the card into a standard SD (Secure Digital) or MMC
(MultiMediaCard) card slot on a PC or PG. The PLC is in stop mode when the memory card
is removed and your control program is not executed.
Use the Windows file explorer and navigate to the \DataLog directory on the memory card.
All your \*.csv data log files are located in this directory.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
525
Extended instructions
9.9 Recipes and Data logs
Make a copy of the data log files and put the copies on a local drive of your PC. Then, you
can use Excel to open a local copy of a *.csv file and not the original file that is stored on the
memory card.
NOTICE
You can copy, but do not modify or delete data log files on a S7-1200 memory card using a
PC card reader
The standard Web server File Browser page is the recommended tool for viewing,
downloading (copying), and deleting data log files.
Direct browsing of the memory card file system by the Windows Explorer has the risk that
you can accidentally delete/modify data log or other system files which can corrupt a file or
make the memory card unusable.
NOTICE
Effect of data logs on memory cards
To ensure the overall performance and robustness of your system, limit the data log rate to
no faster than every 200 ms.
9.9.2.4
Limit to the size of data log files
Data log files share PLC load memory space with the program, program data, configuration
data, user-defined Web pages, and PLC system data. A large program using internal load
memory requires a large amount of load memory. There might be insufficient free space for
data log files. In this case, you can use a "Program card" (Page 145) to increase the size of
load memory. S7-1200 CPUs can use either internal or external load memory, but not both
at once.
Maximum size rule for Data log files
The maximum size of one data log file cannot exceed the free load memory size or 500
megabytes, whichever is smaller. The size of 500 megabytes in this case refers to the
decimal definition of megabyte, such that the maximum data log file size is 500,000,000
bytes or 500 x 10002 bytes.
Table 9- 217 Load memory size
Data area
CPU 1211C
CPU 1212C
CPU 1214C
CPU 1215C,
CPU 1217C
Data storage
Internal load memory
flash memory
1 MB
2 MB
4 MB
4 MB
External load memory
Optional "Program card"
flash memory
4 MB, 12 MB, 24 MB, 256 MB, 2 GB, or 32 GB depending on the SD
card size
User program and
program data, configuration data, Data
logs, user-defined
Web pages, and
PLC system data
S7-1200 Programmable controller
526
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Determining load memory free space
The amount of load memory free space varies during normal operations as the operating
system uses and releases memory. Use the following steps to view the load memory
memory size.
1. Establish an online connection between STEP 7 and the target S7-1200 PLC.
2. Download the program that controls your data log operations.
3. Create any optional user-defined Web pages that you need. The standard Web pages
that access data logs are stored in PLC firmware and do not use load memory.
4. Use the Online and diagnostic tools (Page 1309) or the Web server Diagnostics page
(Page 1019)to view total load memory size and free space.
Calculating the size of a data log file (all data records)
When the data log file is created the CPU allocates the maximum memory size. In addition to
the size required for all the data records, you must include storage space for a data log
header (if used), time stamp header (if used), record index header, and the minimum block
size for memory allocation.
Use the following formula to determine the size of your data log files and ensure you do not
violate the maximum size rule.
Data log data bytes = ((data bytes in one record + time stamp bytes + 12 bytes) * number of
records)
Header
Data log header bytes = header character bytes + 2 bytes
Header character bytes
● No data header and no timestamps = 7 bytes
● No data header and timestamps (has a timestamp header) = 21 bytes
● Data headers and no timestamps = number of character bytes in all column head text
including separator commas
● Data headers and timestamps (has a timestamp header) = number of character bytes in
all column head text including separator commas +21 bytes
Data
Data log data bytes = ((data bytes in one record + time stamp bytes + 12 bytes) * number of
records)
Data bytes in one data record
The DataLogCreate DATA parameter points to a structure that assigns the number of data
fields and the data type of each data field for one data log record.
Multiply the number of occurrences for a given data type by the number of bytes required.
Repeat the process for each data type in a record and sum all the data bytes to get the total
of all data elements in one record.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
527
Extended instructions
9.9 Recipes and Data logs
Size of individual data elements
Log data is stored as character bytes in the CSV (comma separated values) file format. The
following table shows the number of bytes that are required to store each data element.
Data type
Number of bytes (includes data plus one comma byte)
Bool
2
Byte
5
Word
7
DWord
12
Char
4
String
Example 1: MyString String[10]
The maximum string size is assigned as 10 characters.
Text characters + automatic padding with blank characters = 10 bytes
Opening and closing double quote + comma characters = 3 bytes
10 + 3 = 13 total bytes
Example 2: Mystring2 String
If no size is assigned with square brackets, then 254 bytes is allocated by default.
Text characters + automatic padding with blank characters = 254 bytes
Opening and closing double quote + comma characters = 3 bytes
254 + 3 = 257 total bytes
USInt
5
UInt
7
UDInt
12
SInt
5
Int
7
DInt
12
Real
16
LReal
25
Time
15
DTL
24
Number of records in a data log file
The RECORDS parameter of the DataLogCreate instruction sets the maximum number of
records in a data log file.
Time stamp bytes in one data record
● No time stamp = 0 bytes
● Time stamp = 20 bytes
S7-1200 Programmable controller
528
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
9.9.2.5
Data log example program
This Data log example program does not show all the program logic necessary to get sample
values from a dynamic process, but does show the key operations of the Data log
instructions. The structure and number of log files that you use depends on your process
control requirements.
Note
General usage of Data log files
• Data log files are automatically opened after the DataLogCreate and DataLogNew File
operations.
• Data log files are automatically closed after a PLC run to stop transition or a PLC power
cycle.
• A Data log file must be open before a DataLogWrite operation is possible.
• A maximum of eight data log files may be open at one time. More than eight data log files
may exist, but some of them must be closed so no more than eight are open.
Example Data log program
Example data log names, header text, and the MyData structure are created in a data block.
The three MyData variables temporarily store new sample values. The process sample
values at these DB locations are transferred to a data log file by executing the DataLogWrite
instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
529
Extended instructions
9.9 Recipes and Data logs
Network 1 REQ rising edge starts the data log creation process.
Network 2 Capture the DONE output from DataLogCreate because it is only valid for one
scan.
Network 3 If an error exists save the status output
Network 4 A positive edge signal triggers when to store new process values in the MyData
structure.
S7-1200 Programmable controller
530
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Network 5 The EN input state is based upon when the DataLogCreate operation is complete.
A create operation extends over many scan cycles and must be complete before executing a
write operation. The positive edge signal on the REQ input is the event that triggers an
enabled write operation.
Network 6 Close the data log once the last record has been written. After executing the
DataLogWrite operation that writes the last record, the log file full status is signaled when
DataLogWrite STATUS output = 1.
Network 7 A positive signal edge DataLogOpen REQ input simulates the user pushing a
button on an HMI that opens a data log file. If you open a Data log file that has all records
filled with process data, then the next DataLogWrite operation will overwrite the oldest
record. You may want to preserve the old Data log and instead create a new data log, as
shown in network 7.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
531
Extended instructions
9.9 Recipes and Data logs
Network 8 The ID parameter is an IN/OUT type. First, you supply the ID value of the existing
Data log whose structure you want to copy. After the DataLogNewFile operation is complete,
a new and unique ID value for the new Data log is written back to the ID reference location.
The required DONE bit = TRUE capture is not shown, refer to networks 1, 2, and 4 for an
example of DONE bit logic.
Data log files created by the example program viewed with the S7-1200 CPU Web server
①
②
The "Delete" option is not available if you are not logged in with modify privileges.
The "Rename" option is not available if you are not logged in with modify privileges.
S7-1200 Programmable controller
532
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.9 Recipes and Data logs
Table 9- 218 Downloaded .csv file examples viewed with Excel
Two records written in a five record maximum file
Five records in a Data log file with a five
record maximum
After one additional record is written to the
file above which is full, the sixth write
operation overwrites the oldest record one
with record six. Another write operation
will overwrite record two with record seven and so on.
Note
Data logs no longer use an //END marker to mark the end of a data log file that is not full.
Prior to V4.1 of the S7-1200 CPU, data logs that were not full included an //END marker.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
533
Extended instructions
9.10 Data block control
9.10
Data block control
9.10.1
CREATE_DB (Create data block)
Table 9- 219 CREATE_DB instruction
LAD / FBD
SCL
ret_val := CREATE_DB(
REQ:=_bool_in_,
LOW_LIMIT:=_uint_in_,
UP_LIMIT:=_uint_in_,
COUNT:=_udint_in_,
ATTRIB:=_byte_in_,
BUSY=>_bool_out_,
DB_NUM=>_uint_out_);
Description
Use the instruction "CREATE_DB" to create a
new data block in the load and/or work memory.
The instruction "CREATE_DB" does not change
the checksum of the user program.
A data block that you create only in work memory
has the following properties:
•
After a memory reset or POWER OFF /
POWER ON this block no longer exists.
•
When loading or when there is a STOP-RUN
transition, its content remains unchanged.
Number of the data block
The data block created is assigned a number from the range defined at the LOW_LIMIT (low
limit) and UP_LIMIT (high limit) parameters. "CREATE_DB" assigns the smallest possible
number from the specified range to the DB. You cannot assign the numbers of the DBs
already contained in the user program.
To create a DB with a specific number, enter the same number for the high and low limit of
the range to be specified. If a DB with the same number already exists in the work memory
and/or load memory, or if the DB exists as a copied version, the instruction will be terminated
and an error message will be generated at the RET_VAL parameter.
Start values of the data block
The SRCBLK parameter is used to define start values for the DB that is to be created. The
SRCBLK parameter is a pointer to a DB or a DB area from which you apply the start values.
The DB addressed at the SRCBLK parameter must have been generated with standard
access ("Optimized block access" attribute disabled).
● If the area specified at the SRCBLK parameter is larger than the DB generated, the
values up to the length of the DB generated will be applied as start values.
● If the area specified at the SRCBLK parameter is smaller than the DB generated, the
remaining values will be filled with "0".
To ensure data consistency, you must not change this data area while "CREATE_DB" is
being executed (which means as long as the BUSY parameter has the value TRUE).
S7-1200 Programmable controller
534
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.10 Data block control
Functional description
The "CREATE_DB" instruction works asynchronously. Processing takes place across
several calls. You start the job by calling "CREATE_DB" with REQ = 1.
The output parameters RET_VAL and BUSY indicate the status of the job.
See also: DELETE_DB (Delete data block) (Page 542)
Parameters
The following table shows the parameters of the "CREATE_DB" instruction:
Parameter
Declaration
Data
type
Memory area
Description
REQ
Input
BOOL
I, Q, M, D, L or constant
Level-triggered control parameter "request to activate"
LOW_LIMIT Input
UINT
I, Q, M, D, L or constant
Low limit of the range for the assignment of a DB number. The
smallest possible number is 60000.
UP_LIMIT
Input
UINT
I, Q, M, D, L or constant
High limit of the area used by "CREATE_DB" to assign a number to your DB (largest possible DB number: 60999)
COUNT
Input
UDINT
I, Q, M, D, L or constant
The count value specifies the number of bytes which you want
to reserve for the DB generated. The number of bytes must be
an even number. The maximum length is 65534 bytes.
ATTRIB
Input
BYTE
I, Q, M, D, L or constant
You use the first 4 bits of the byte at parameter ATTRIB to
define the properties of the data block *:
REQ = 1: Request to generate the data block
•
Bit 0 = 0: Attribute "Only store in load memory" is not set.
Bit 0 = 1: Attribute "Only store in load memory" is set. With
this setting, the DB takes up no space in the work memory
and is not included in the program. The DB cannot be accessed with bit commands. When bit 0 = 1, the selection for
bit 2 is irrelevant.
To ensure compatibility with STEP 7 V5.x, bits 0 and 3 must be
considered together (see below).
•
•
Bit 1 = 0: Attribute "Data block write-protected in the device"
is not set.
•
Bit 1 = 1: Attribute "Data block write-protected in the device"
is set.
•
Bit 2 = 0: DB is retentive (only for DBs generated in the load
and in the work memory). The DB is regarded as retentive if
at least one value has been set as retentive.
• Bit 2 = 1: DB is not retentive
Retentivity is not supported with DBs that are only stored in
load memory or only in the work memory. If you call the
"CREATE_DB" instruction with one of the two combinations
"retentive and only load memory" or "retentive and only work
memory" the DB to be generated will not be marked as retentive.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
535
Extended instructions
9.10 Data block control
Parameter
Declaration
Data
type
Memory area
Description
•
Bit 3 = 0: Creation of the DB either in the load memory or in
the work memory (selection using bit 0, see above)
Bit 3 = 1: Creation of the DB both in the load memory and in
the work memory (bit 0 irrelevant)
To ensure compatibility with STEP 7 V5.x, bits 0 and 3 must be
used in combination. When bit 3 = 1, bit 0 is irrelevant.
•
Bit 0
Bit 3
DB generation
0
0
In work memory only
1
0
In load memory only
Irrelevant
1
Work and load memory
•
Bit 4 = 0 - No start values specified (input values at the
SRCBLK parameter will be ignored).
•
Bit 4 = 1 - Specify start values (values correspond to the DB
addressed by the SRCBLK parameter).
SRCBLK
Input
VARIAN
T
D
Pointer to the data block whose values will be used to initialize
the data block to be generated.
RET_VAL
Return
INT
I, Q, M, D, L
Error information
BUSY
Output
BOOL
I, Q, M, D, L
BUSY = 1: The process is not yet complete.
DB_NUM
Output
DB_DY
N
(UINT)
I, Q, M, D, L
Number of the DB created.
* The properties selected here correspond to the attributes in the properties of a data block.
You can find additional information on valid data types under "Data types (Page 125)".
S7-1200 Programmable controller
536
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.10 Data block control
Parameter RET_VAL
Error code*
(W#16#...)
Description
0000
No error
0081
The destination area is greater than the source area.
The source area is written completely to the destination area. The remaining bytes of the destination area
remain unchanged.
7000
First call with REQ = 0: No data transfer active; BUSY has the value "0".
7001
First call with REQ = 1: Data transfer triggered; BUSY has the value "1".
7002
Intermediate call (REQ irrelevant): Data transfer already active; BUSY has the value "1".
8081
The source area is larger than the destination area.
The complete destination area is written. The remaining bytes of the source area are ignored.
8092
The "Create data block" function is currently unavailable because
•
The "Compress user memory" function is currently active.
•
The maximum number of blocks on your CPU has already been reached.
8093
No data block or a data block that is not in the work memory is specified for the SRCBLK parameter.
8094
An invalid value was specified at parameter ATTRIB.
80A1
DB number error:
•
80A2
The number is "0"
•
The number exceeds the CPU-specific high limit for DB numbers
•
Low limit > high limit
DB length error:
•
The length is "0"
•
The length is an odd number
•
The length is greater than permitted by the CPU
80A3
The data block at the SRCBLK parameter was not created with standard access.
80B1
There is no DB number free.
80B2
Not enough work memory.
80B4
The memory card is write-protected.
80BB
Not enough load memory.
80C3
The maximum number of simultaneously active "CREATE_DB" instructions has already been reached.
General error See also: Common error codes for the Extended instructions (Page 553)
information
* You can display the error code as either integer or hexadecimal values in the program editor.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
537
Extended instructions
9.10 Data block control
9.10.2
READ_DBL and WRIT_DBL (Read/write a data block in load memory)
instructions
Table 9- 220 READ_DBL and WRIT_DBL instructions
LAD / FBD
SCL
READ_DBL(
req:=_bool_in_,
srcblk:=_variant_in_,
busy=>_bool_out_,
dstblk=>_variant_out_);
WRIT_DBL(
req:=_bool_in_,
srcblk:=_variant_in_,
busy=>_bool_out_,
dstblk=>_variant_out_);
Description
Copies DB start values or part of the
values, from load memory to a target
DB in the work memory.
The content of load memory is not
changed during the copy process.
Copies DB current values or part of the
values from work memory to a target
DB in load memory.
The content of work memory is not
changed during the copy process.
Table 9- 221 Data types for the parameters
Parameter and type
Data type
Description
REQ
IN
BOOL
A high signal starts the operation, if BUSY = 0.
SRCBLK
IN
VARIANT
READ_DBL: Pointer to the source data block in load memory
RET_VAL
OUT
INT
Execution condition code
BUSY
OUT
BOOL
BUSY = 1 signals that the reading/writing process is not complete.
DSTBLK
OUT
VARIANT
READ_DBL: Pointer to the destination data block in work memory
WRIT_DBL: Pointer to the source data block in work memory
WRIT_DBL: Pointer to the destination data block in load memory
Typically, a DB is stored in both load memory (flash) and work memory (RAM). The start
values (initial values) are always stored in load memory, and the current values are always
stored in work memory. READ_DBL can be used to copy a set of start values from load
memory to the current values of a DB in work memory that is referenced by your program.
You can use WRIT_DBL to update the start values stored in internal load memory or
memory card from current values in work memory.
Note
Effect of WRIT_DBL and READ_DBL instruction on flash memory
The WRIT_DBL instruction performs write operations in flash memory (internal load memory
or memory card). To avoid reducing the lifetime of the flash memory, use the WRIT_DBL
instruction for infrequent updates such as recording changes to a production process. For
similar reasons, avoid frequent calls to READ_DBL for read operations.
S7-1200 Programmable controller
538
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.10 Data block control
You must create the data blocks for READ_DBL and WRIT_DBL prior to calling these
instructions in the STEP 7 program. If you created the source DB as a "standard" type then
the destination DB must also be the "standard" type. If you created the source data block as
an "optimized" type then the destination data block must also be the "optimized" type.
If the DBs are standard, then you can specify either a tag name or a P# value. The P# value
allows you to specify and copy any number of elements of the specified size (Byte, Word, or
DWord). Thus, you can copy part or all of a DB. If the DBs are optimized, you can only
specify a tag name; you cannot use the P# operator. If you specify a tag name for either
standard or optimized DBs (or for other work-memory types), then the instruction copies the
data that this tag name references. This could be a user-defined type, an array, or a basic
element. You can only use type Struct with these instructions if the DB is standard, not
optimized. You must use a user-defined type (UDT) if it is a structure in optimized memory.
Only a user-defined type ensures that the "data types" are exactly the same for both the
source and destination structures.
Note
Using a structure (data type Struct) in an "optimized" DB
When using a Struct data type with "optimized" DBs, you must first create a user-defined
data type (UDT) for the Struct. You then configure both the source and destination DBs with
the UDT. The UDT ensures that the data types within the Struct remain consistent for both
DBs.
For "standard" DBs, you use the Struct without creating a UDT.
READ_DBL and WRIT_DBL execute asynchronously to the cyclic program scan. The
processing extends over multiple READ_DBL and WRIT_DBL calls. You start the DB
transfer job by calling with REQ = 1 and then monitor the BUSY and RET_VAL outputs to
determine when the data transfer is complete and correct.
Note
Effect of WRIT_DBL and READ_DBL instruction on communication load
When the WRIT_DBL or READ_DBL instruction is continually active, it can consume
communication resources to the point that STEP 7 loses communication with the CPU. For
this reason, use a positive edge input (Page 233) for the REQ parameter rather than a
normally open or closed input (Page 227) that would remain on (signal level high) for multiple
scans.
To ensure data consistency, do not modify the destination area during the processing of
READ_DBL or the source area during the processing of WRIT_DBL (that is, as long as the
BUSY parameter is TRUE).
SRCBLK and DSTBLK parameter restrictions:
● A data block must have been previously created before it can be referenced.
● The length of a VARIANT pointer of type BOOL must be divisible by 8.
● The length of a VARIANT pointer of type STRING must be the same in the source and
destination pointers.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
539
Extended instructions
9.10 Data block control
Recipes and machine setup information
You can use the READ_DBL and WRIT_DBL instructions to manage recipes or machine
setup information. This essentially becomes another method of achieving retentive data for
values that do not change often, although you would want to limit the number of writes to
prevent wearing out the flash prematurely. This effectively allows you to increase the amount
of retentive memory beyond that supported for the normal power-down retentive data, at
least for values that do not change often. You could save recipe information or machinesetup information from work memory to load memory using the WRIT_DBL instruction, and
you could retrieve such information from load memory into work memory using the
READ_DBL instruction.
Table 9- 222 Condition codes
RET_VAL
Description
(W#16#...)
0000
No error
0081
Warning: that the source area is smaller than the destination area. The source data is copied completely with the extra bytes in the destination area unchanged.
7000
Call with REQ = 0: BUSY = 0
7001
First call with REQ = 1 (working): BUSY = 1
7002
Nth call (working): BUSY = 1
8051
Data block type error
8081
The source area is larger than the destination area. The destination area is completely filled and the
remaining bytes of the source are ignored.
8251
Source data block type error
82B1
Missing source data block
82C0
The source DB is being edited by another statement or a communication function.
8551
Destination data block type error
85B1
Missing destination data block
85C0
The destination DB is being edited by another statement or a communication function.
80C3
More than 50 READ_DBL or 50 WRIT_DBL statements are currently queued for execution.
See also Recipes (Page 498)
S7-1200 Programmable controller
540
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.10 Data block control
9.10.3
ATTR_DB (Read data block attribute)
Table 9- 223 ATTR_DB instruction
LAD / FBD
SCL
ret_val := ATTR_DB(
REQ:=_bool_in_,
DB_NUMBER:=_uint_in_,
DB_LENGTH=>_udint_out_,
ATTRIB=>_byte_out_);
Description
You use the instruction "ATTR_DB" to obtain
information about a data block (DB) located in the
work memory of the CPU. The instruction determines the attributes set at the ATTRIB parameter
for the DB selected.
The length cannot be read out for data blocks
with optimized access and data blocks that are
only in load memory. In these cases, the
DB_LENGH parameter has the value "0".
Do not apply ATTR_DB to data blocks with optimized access and activated memory reserve.
Do not read out the data blocks for motion control
with the "ATTR_DB" instruction. The error code
80B2 is output for this.
Parameters
The following table shows the parameters of the "ATTR_DB" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, D, L or constant
REQ = 1: Request to read block attributes
DB_NUMBE
R
Input
DB_ANY
I, Q, M, D, L or constant
Number of the DB to be tested
RET_VAL
Output
INT
I, Q, M, D, L
Error information
UDINT
I, Q, M, D, L
•
Number of data bytes that the selected DB contains.
•
"0" for data blocks with optimized access and
data blocks that are only in load memory.
DB_LENGTH Output
ATTRIB
Output
BYTE
I, Q, M, D, L
DB properties:
•
Bit 0*= 0: Attribute "Only store in load memory" is
not set.
•
Bit 0*= 1: Attribute "Only store in load memory" is
set.
•
Bit 1 = 0: Attribute "Data block write-protected in
the device" is not set.
•
Bit 1 = 1: Attribute "Data block write-protected in
the device" is set.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
541
Extended instructions
9.10 Data block control
Parameter
Declaration
Data type
Memory area
Description
If bit 0 = 1, then bit 2 is irrelevant and gets the value
1.
•
Bit 2 = 0: Retentive - The DB is regarded as retentive if at least one value has been set as retentive.
•
Bit 2 = 1: Not retentive - The complete DB is not
retentive.
•
Bit 3*= 0: The DB is either in the load memory (bit
0 = 1) or in the work memory (bit 0 = 0).
•
Bit 3*= 1: The DB is generated in both the load
and the work memory
* The relationship between bit 0 and bit 3 is explained in the parameters of the instruction "CREATE_DB (Create data
block) (Page 534)".
You can find additional information on valid data types under "Data types (Page 125)".
Parameter RET_VAL
Error code*
(W#16#...)
Explanation
0000
No error occurred.
80A1
Error in input parameter DB_NUMBER: the actual parameter selected
•
Is "0"
•
Is greater than the maximum permitted DB number for the CPU used.
80B1
The DB with the specified number does not exist on the CPU.
80B2
Data blocks of motion control technology objects cannot be read with the "ATTR_DB" instruction.
General error See also: Common error codes for the Extended instructions (Page 553)
information
* You can display the error code as either integer or hexadecimal values in the program editor.
9.10.4
DELETE_DB (Delete data block)
Table 9- 224 DELETE_DB instruction
LAD / FBD
SCL
ret_val := DELETE_DB(
REQ := _bool_in_,
DB_NUMBER :=
_uint_in_,
BUSY => _bool_out_);
Description
You use the instruction "DELETE_DB" to delete a
data block (DB) that the user program created by
calling the instruction "CREATE_DB (Page 534)".
If the data block was not created with
"CREATE_DB", DELETE_DB returns the error
code W#16#80B5 at the RET_VAL parameter.
The DELETE_DB call does not delete the selected data block immediately, but rather at the cycle
control point after execution of the cycle OB.
S7-1200 Programmable controller
542
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.10 Data block control
Functional description
The "DELETE_DB" instruction works asynchronously, that is, its execution extends over
multiple calls. You start the interrupt transfer by calling the instruction with REQ = 1.
Output parameter BUSY and bytes 2 and 3 of output parameter RET_VAL show the status of
the job.
The deletion of the data block is complete when output parameter BUSY has the value
FALSE.
Parameters
The following table shows the parameters of the "DELETE_DB" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, D, L or constant
REQ =1: Request to delete the DB with the number in parameter DB_NUMBER
DB_NUMBER
Input
UINT
I, Q, M, D, L or constant
Number of the DB to be deleted
RET_VAL
Output
INT
I, Q, M, D, L
Error information (see "RET_VAL parameter")
BUSY
Output
BOOL
I, Q, M, D, L
BUSY= 1: The process is not yet complete.
You can find additional information on valid data types under "Data types (Page 125)".
Parameter RET_VAL
Error code*
(W#16#...)
Explanation
0000
No error occurred.
7000
First call with REQ = 0: No data transfer active; BUSY has the value "0".
7001
First call with REQ = 1: Data transfer triggered; BUSY has the value "1".
7002
Intermediate call (REQ irrelevant): Data transfer already active; BUSY has the value "1".
80A1
Error in input parameter DB_NUMBER:
•
The value at the parameter is "0".
•
The value at the parameter is greater than the maximum permitted DB number for the CPU used.
80B1
The DB with the specified number does not exist on the CPU.
80B4
The DB cannot be deleted because the memory card of the CPU is write-protected.
80B5
The DB was not created using "CREATE_DB".
80BB
Not enough load memory.
80C3
The "Delete a DB" function cannot be executed at this time due to a temporary resource bottleneck.
General error
information
See also: Common error codes for the Extended instructions (Page 553)
* You can display the error code as either integer or hexadecimal values in the program editor.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
543
Extended instructions
9.11 Address handling
9.11
Address handling
9.11.1
GEO2LOG (Determine the hardware identifier from the slot)
You use the GEO2LOG instruction to determine the hardware identifier based upon slot
information.
Table 9- 225 GEO2LOG instruction
LAD / FBD
SCL
ret_val := GEO2LOG(
GEOADDR:=_variant_in_out_,
laddr:=_word_out_);
Description
You use the GEO2LOG instruction to
determine the hardware identifier based
upon slot information.
The GEO2LOG instruction determines the hardware identifier based upon slot information
that you define using the GEOADDR system data type:
Depending on the type of hardware you define at the parameter HWTYPE, the following
information is evaluated from the other GEOADDR parameters:
● With HWTYPE = 1 (PROFINET IO system):
– Only IOSYSTEM is evaluated. The other parameters of GEOADDR are not taken into
consideration.
– The hardware identifier of the PROFINET IO system is output.
● With HWTYPE = 2 (PROFINET IO device):
– IOSYSTEM and STATION are evaluated. The other parameters of GEOADDR are not
taken into consideration.
– The hardware identifier of the PROFINET IO device is output.
● With HWTYPE = 3 (rack):
– Only IOSYSTEM and STATION are evaluated. The other parameters of GEOADDR
are not taken into consideration.
– The hardware identifier of the rack is output.
● With HWTYPE = 4 (module):
– IOSYSTEM, STATION, and SLOT are evaluated. The SUBSLOT parameter of
GEOADDR is not taken into consideration.
– The hardware identifier of the module is output.
S7-1200 Programmable controller
544
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.11 Address handling
● With HWTYPE = 5 (submodule):
– All parameters of GEOADDR are evaluated.
– The hardware identifier of the submodule is output.
The AREA parameter of the GEOADDR system data type is not evaluated.
Table 9- 226 Data types for the parameters
Parameter and type
Data type
Description
GEOADDR
Variant
Pointer to the structure of the GEOADDR system data type. The
GEOADDR system data type contains the slot information from which the
hardware ID is determined.
IN/OUT or
IN ?
Refer to the "GEOADDR system data type (Page 551)" for further information.
RET_VAL
OUT or
RETURN
?
Int
Output of error information.
LADDR
OUT
HW_ANY
Hardware identifier of the assembly or the module.
The number is automatically assigned and is stored in the properties in
the hardware configuration.
For further information on valid data types, refer to "Overview of the valid data types" in the
STEP 7 online help.
Table 9- 227 Condition codes
RET_VAL*
Explanation
(W#16#...)
0
No error occurred.
8091
Invalid value for in GEOADDR for HWTYPE.
8094
Invalid value for in GEOADDR for IOSYSTEM.
8095
Invalid value for in GEOADDR for STATION.
8096
Invalid value for in GEOADDR for SLOT.
8097
Invalid value for in GEOADDR for SUBSLOT.
* The error codes can be displayed as integer or hexadecimal values in the program editor.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
545
Extended instructions
9.11 Address handling
9.11.2
LOG2GEO (Determine the slot from the hardware identifier)
You use the LOG2GEO instruction to determine the geographical address (module slot) from
the logical address belonging to a hardware identifier.
Table 9- 228 LOG2GEO instruction
LAD / FBD
SCL
ret_val := LOG2GEO(
laddr:=_word_in_,
GEOADDR:=_variant_in_out_);
Description
You use the LOG2GEO instruction to
determine the module slot belonging to a
hardware identifier.
The LOG2GEO instruction determines the geographic address of a logical address based
upon the hardware identifier:
● Use the LADDR parameter to select the logical address based upon the hardware
identifier.
● The GEOADDR contains the geographic address of the logical address given at the
LADDR input.
Note
In the cases where the HW type does not support a component, a subslot number for a
module 0 is returned.
An error is provided if the LADDR input does not address a HW object.
S7-1200 Programmable controller
546
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.11 Address handling
Table 9- 229 Data types for the parameters
Parameter and type
Data type
Description
LADDR
IN
HW_ANY
Hardware identifier of the IO system or the module. The number is assigned automatically and is stored in the properties of the CPU or the
interface of the hardware configuration.
RET_VAL
OUT
Int
Error code of the instruction
GEOADDR
IN_OUT
Variant
Pointer to the GEOADDR system data type. The GEOADDR system data
type contains the slot information.
Refer to the "GEOADDR system data type (Page 551)" for further information.
For further information on valid data types, refer to "Overview of the valid data types" in the
STEP 7 online help.
Table 9- 230 Condition codes
RET_VAL
Description
(W#16#...)
0000
No error
8090
The address specified at the LADDR parameter is invalid.
* The error codes can be displayed as integer or hexadecimal values in the program editor.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
547
Extended instructions
9.11 Address handling
9.11.3
IO2MOD (Determine the hardware identifier from an I/O address)
You use the IO2MOD instruction to determine the hardware identifier of the module from an
I/O address of a (sub)module.
Table 9- 231 IO2MOD instruction
LAD / FBD
SCL
ret_val := IO2MOD(
ADDR:=_word_in_,
LADDR:=_word_out_);
Description
You use the IO2MOD instruction to determine the module slot belonging to a
hardware identifier.
The IO2MOD instruction determines the hardware identifier of the module from an IO
address (I, Q, PI, PQ) of a (sub)module.
Enter the IO address at the ADDR parameter. If a series of IO addresses is used at this
parameter, only the first address is evaluated to determine the hardware identifier. If the first
address is correctly specified, the length for the address specification at the ADDR is of no
significance. If an address area is used that encompasses several modules or non-used
addresses, the hardware identifier of the first module can also be determined.
If no IO address of a (sub)module is specified at the ADDR parameter, the error code "8090"
is output at the RET_VAL parameter.
Note
Input of IO address in SCL
You cannot program using the IO access ID "%QWx:P" in SCL. In this case, use the
symbolic tag name or the absolute address in the process image.
S7-1200 Programmable controller
548
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.11 Address handling
Table 9- 232 Data types for the parameters
Parameter
Declaration
Data type
Memory area
Description
ADDR
IN or IN/OUT ?
Variant
I, Q, M, D, L
IO address (I, Q, PI, PQ) within a
(sub)module.
Make sure that slice access is not used for
the parameter ADDR. If this is the case, incorrect values are output at the LADDR parameter.
RET_VAL
OUT or
RETURN ?
Int
I, Q, M, D, L
Error code of the instruction.
LADDR
OUT
HW_IO
I, Q, M, D, L
Determined hardware identifier (logical address) of the IO (sub)module.
For further information on valid data types, refer to "Overview of the valid data types" in the
STEP 7 online help.
Table 9- 233 Condition codes
RET_VAL*
(W#16#...)
Explanation
0
No error occurred.
8090
IO address specified at ADDR parameter is not used by any hardware component.
* The error codes can be displayed as integer or hexadecimal values in the program editor.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
549
Extended instructions
9.11 Address handling
9.11.4
RD_ADDR (Determine the IO addresses from the hardware identifier)
You use the RD_ADDR instruction to get the I/O addresses of a submodule.
Table 9- 234 RD_ADDR instruction
LAD / FBD
SCL
ret_val := RD_ADDR(
laddr:=_word_in_,
PIADDR=>_udint_out_,
PICount=>_uint_out_,
PQADDR=>_udint_out_,
PQCount=>_uint_out_,);
Description
You use the RD_ADDR instruction to get the
I/O addresses of a submodule.
The RD_ADDR instruction determines the length and the start address of the inputs or
outputs based on the hardware identifier of a submodule:
● Use the LADDR parameter to select the input or output module based upon the hardware
identifier.
● The following output parameters are used depending on whether it is an input module or
output module:
– In the case of an input module, the determined values are output at the PIADDR and
PICOUNT parameters.
– In the case of an output module, the determined values are output at the PQADDR
and PQCOUNT parameters.
● The PIADDR and PQADDR parameters each contain the start address of the I/O
addresses of the module.
● The PICOUNT and PQCOUNT parameters each contain the number of bytes of the
inputs or outputs (1 byte for 8 inputs/outputs, 2 bytes for 16 inputs/outputs).
S7-1200 Programmable controller
550
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.11 Address handling
Table 9- 235 Data types for the parameters
Parameter and type
Data type
Description
LADDR
IN
HW_IO
Hardware identifier of the (sub)module
RET_VAL
OUT
Int
Error code of the instruction
PIADDR
OUT
UDInt
Start address of the input module
PICOUNT
OUT
UInt
Number of bytes of the inputs
PQADDR
OUT
UDInt
Start address of the output module
PQCOUNT
OUT
UInt
Number of bytes of the outputs
For further information on valid data types, refer to "Overview of the valid data types" in the
STEP 7 online help.
Table 9- 236 Condition codes
RET_VAL
Description
(W#16#...)
0000
No error
8090
Hardware identifier of the module at the LADDR parameter is invalid.
* The error codes can be displayed as integer or hexadecimal values in the program editor.
9.11.5
GEOADDR system data type
Geographical address
The system data type GEOADDR contains the geographical address of a module (or the slot
information).
● Geographical address for PROFINET IO:
For PROFINET IO, the geographical address is composed of the ID of the PROFINET IO
system, the device number, the slot number, and the submodule (if a sub-module is
used).
● Geographical address for PROFIBUS DP:
For PROFIBUS DP, the geographical address consists of the ID of the DP master
system, the station number, and the slot number.
The slot information of the modules can be found in the hardware configuration of each
module.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
551
Extended instructions
9.11 Address handling
Structure of the GEOADDR system data type
The structure GEOADDR is automatically created if you enter "GEOADDR" as the data type
in a data block.
Parameter name
GEOADDR
HWTYPE
Data type
Description
STRUCT
UINT
Hardware type:
•
1: IO system (PROFINET/PROFIBUS)
•
2: IO device/DP slave
•
3: Rack
•
4: Module
• 5: Submodule
If a hardware type is not supported by the instruction, a HWTYPE "0" is output.
AREA
UINT
Area ID:
•
0 = CPU
•
1 = PROFINET IO
•
2 = PROFIBUS DP
•
3 = AS-i
IOSYSTEM
UINT
PROFINET IO system (0=central unit in the rack)
STATION
UINT
•
Number of the rack if area identifier AREA = 0 (central module).
•
Station number if area identifier AREA > 0.
SLOT
UINT
Slot number
SUBSLOT
UINT
Number of the submodule. This parameter has the value "0" if no submodule is
available or can be plugged.
S7-1200 Programmable controller
552
System Manual, V4.2, 09/2016, A5E02486680-AK
Extended instructions
9.12 Common error codes for the Extended instructions
9.12
Common error codes for the Extended instructions
Table 9- 237 Common condition codes for the extended instructions
Condition code (W#16#....)1
Description
8x222
Area too small for input
8x23
Area too small for output
8x24
Illegal input area
8x25
Illegal output area
8x28
Illegal input bit assignment
8x29
Illegal output bit assignment
8x30
Output area is a read-only DB.
8x3A
DB does not exist.
1
If one of these errors occurs when a code block is executed, then the CPU remains in RUN (default) or can be configured to go to STOP. Optionally, you can use the GetError or GetErorID instructions within that code block to handle the
error locally (CPU remains in RUN), and create a programmed reaction to the error.
2
The "x" represents the parameter number with the error. Parameter numbers start with 1.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
553
Extended instructions
9.12 Common error codes for the Extended instructions
S7-1200 Programmable controller
554
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1
10
Counting (High-speed counters)
The basic counter instructions, described in "Counter operations" (Page 244), are limited to
counting events that occur at a rate slower than the scan cycle of the S7-1200 CPU. The
High-speed counter (HSC) function provides the ability to count pulses occurring at a higher
rate than the PLC scan cycle. In addition, you can configure the HSC to measure the
frequency and period of the occurring pulses, or be setup such that motion control can use
the HSC to read a motor encoder signal.
To use the HSC function, the HSC must first be enabled and configured using the CPU’s
Properties tab in the Device Configuration screen. To get started configuring the HSC, refer
to "Configuring a high-speed counter" (Page 572).
After you download the hardware configuration, the HSC can count pulses or measure
frequency without the need for any instructions to be called. When the HSC is in Count or
Period mode, the count value is automatically captured and updated in the process image (I
memory) each scan cycle. If the HSC is in Frequency mode, the process image value is the
frequency in Hz.
In addition to counting and measuring, the HSC can generate hardware interrupt events,
operate dependent on the state of physical input points, and produce an output pulse
according to a specified counter event (V4.2 or above CPUs only). Technology instruction
CTRL_HSC_EXT allows the user program to control the HSC programmatically.
CTRL_HSC_EXT updates HSC parameters and returns the most up-to-date values when
executed. You can use the CTRL_HSC_EXT instruction while the HSC is in Count, Period,
or Frequency mode.
Note
The CTRL_HSC_EXT instruction replaces the legacy CTRL_HSC instruction for projects
targeting V4.2 CPUs and later. All of the functionality of the CTRL_HSC instruction, plus
several additional features, is available with the CTRL_HSC_EXT instruction. The legacy
CTRL_HSC instruction is only available for compatibility with older S7-1200 projects and
should not be used in new projects.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
555
Technology instructions
10.1 Counting (High-speed counters)
10.1.1
CTRL_HSC_EXT (Control high-speed counter) instruction
10.1.1.1
Instruction overview
Table 10- 1
CTRL_HSC_EXT instruction
LAD / FBD
SCL
"CTRL_HSC_1_DB" (
hsc:=_hw_hsc_in_,
done:=_done_out_,
busy:=_busy_ out_,
error:=_error_out_,
status:=_status_out_,
ctrl:=_variant_in_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "CTRL_HSC_1_DB" is the name of the instance DB.
Table 10- 2
Parameter
Description
Each CTRL_HSC_EXT (Control highspeed counter (extended)) instruction
uses a system-defined data structure
stored in a user-defined Global DB to
store counter data. You assign the
HSC_Count, HSC_Period, or
HSC_Frequency data types as an input
parameter to the CTRL_HSC_EXT instruction.
Data types for the parameters
Declaration
Data type
Description
HSC
IN
HW_HSC
HSC identifier
CTRL
IN_OUT
Variant
SFB input and return data.
Note: Refer to "CTRL_HSC_EXT instruction System Data
Types (SDT) (Page 561)" for further information.
DONE
OUT
Bool
1= Indicates SFB is finished. Always 1 because SFB is synchronous
BUSY
OUT
Bool
Always 0, function is never busy
ERROR
OUT
Bool
1 = Indicates an error
STATUS
OUT
Word
Execution condition code
Note: Refer to the "Execution condition codes" table below for
further information.
Table 10- 3
Execution condition codes
STATUS (W#16#)
Description
0
No error
80A1
HSC identifier does not address an HSC
80B1
Illegal value in NewDirection
80B4
Illegal value in NewPeriod
80B5
Illegal value in NewOpModeBehavior
80B6
Illegal value in NewLimitBehavior
80D0
SFB 124 not available
S7-1200 Programmable controller
556
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.1.2
Example
To use the CTRL_HSC_EXT instruction, follow the steps below:
1. Place the CTRL_HSC_EXT instruction in the ladder network, which also creates the
following instance data block: "CTRL_HSC_EXT_DB":
2. Attach the HSC’s hardware identifier, found in the HSC’s properties, to the "HSC" pin of
the ladder instruction. You can also select one of the six "Hw_Hsc" objects from the
dropdown menu of this input pin. The default tag name for HSC1 is "Local~HSC_1":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
557
Technology instructions
10.1 Counting (High-speed counters)
3. Create a global data block named "Data_block_1" (You can also use an existing global
data block.):
– Within "Data_block_1", locate an empty row and add a variable named "MyHSC".
– In the "Data type" column, add one of the following System Data Types (SDT). Select
the SDT that corresponds to the HSC’s configured type of counting. More HSC SDT
information can be found later in this section. The dropdown list does not contain
these types so ensure that you enter the SDT name exactly as shown: HSC_Count,
HSC_Period, or HSC_Frequency
– After you enter the data type, you can expand the "MyHSC" variable to see all the
fields contained in the data structure. Here, you can find the data type of each of the
fields and change the default starting values:
S7-1200 Programmable controller
558
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
4. Assign the variable "'Data_block_1'. MyHSC" to the CTRL input pin of the
CTRL_HSC_EXT instruction:
– Select "Data_Block_1".
– Select "MyHSC".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
559
Technology instructions
10.1 Counting (High-speed counters)
– Delete the period (".") following: "'Data_Block_1'.MyHSC". Then, either click outside
the box or press the ESC key once and then press the Enter key.
Note
After deleting the period (".") following: "'Data_Block_1'.MyHSC", do not press only the
Enter key. This action places the period (".") back into the box.
– The completed CTRL input is shown below.
After you configure the HSC in the PLC, you can execute the CTRL_HSC_EXT instruction. If
an error occurs, ENO is set to "0" and the STATUS output indicates the condition code.
See also
CTRL_HSC_EXT Instruction System Data Types (SDT) (Page 561)
S7-1200 Programmable controller
560
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.1.3
CTRL_HSC_EXT Instruction System Data Types (SDT)
The following System Data Types (SDTs) are only used with the CTRL_HSC_EXT
instruction’s CTRL pin. To use them, create a user data block and add an object with the
data type of the SDT that corresponds to the HSC’s configured mode (type of counting). TIA
Portal V14 does not show these data types in the dropdown menu so the name of the SDT
must be typed exactly as shown.
Inputs of the HSC’s SDT are denoted by the prefix "En" or "New". Inputs prefixed with "En"
either enables an HSC function or updates the corresponding parameter. The prefix "New"
identifies the update value. In order for the new value to take effect, the corresponding "En"
bit must be true, and the "New" value must be valid. When the CTRL_HSC_EXT instruction
is executed, the program applies input changes and updates the outputs with the appropriate
SDT reference attached.
SDT: HSC_Count
The "HSC_Count" data type corresponds to an HSC configured for "Count" mode. The
Count mode provides the following capabilities:
● Access the current pulse count
● Latch the current pulse count on an input event
● Reset the current pulse count to the starting value on an input event
● Access status bits, indicating certain HSC events have occurred
● Disable the HSC using a software or hardware input
● Change the counting direction using a software or hardware input
● Change the current pulse count
● Change the starting value (used when CPU transitions to RUN state or when Sync
function is triggered)
● Changing two independent reference (or preset) values used for comparison
● Change the upper and lower counting limits
● Change how the HSC operates when the pulse count reaches those limits
● Generate a hardware interrupt event when the current pulse count reaches a reference
(preset) value
● Generate a hardware interrupt event when the Synchronization (reset) input activates
● Generate a hardware interrupt event when the counting direction changes based upon an
external input
● Generate a single output pulse on a specified counting event
When an event occurs and the CTRL_HSC_EXT instruction executes, the instruction sets a
status bit. On the following CTRL_HSC_EXT instruction execution, the instruction clears the
status bit, unless the event occurs again before the instruction executes.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
561
Technology instructions
10.1 Counting (High-speed counters)
Table 10- 4
HSC_Count structure
Structure element Declaration
Data type
Description
CurrentCount
OUT
Dint
Returns the HSC’s current count value
CapturedCount
OUT
Dint
Returns the counter value captured on the specified input
event
SyncActive
OUT
Bool
Status bit: Sync input was activated
DirChange
OUT
Bool
Status bit: Counting direction has changed
CmpResult1
OUT
Bool
Status bit: CurrentCount equals Reference1 event occured
CmpResult2
OUT
Bool
Status bit: CurrentCount equals Reference2 event occured
OverflowNeg
OUT
Bool
Status bit: CurrentCount reached the LowerLimit
OverflowPos
OUT
Bool
Status bit: CurrentCount reached the UpperLimit
EnHSC
IN
Bool
Enables the HSC to count pulses when true; disables counting
when false
EnCapture
IN
Bool
Enables the Capture input when true, Capture input has no
effect when false
EnSync
IN
Bool
Enables the Sync input when true; Sync input has no effect
when false
EnDir
IN
Bool
Enables the NewDirection value to take effect
EnCV
IN
Bool
Enables the NewCurrentCount value to take effect
EnSV
IN
Bool
Enables the NewStartValue value to take effect
EnReference1
IN
Bool
Enables the NewReference1 value to take effect
EnReference2
IN
Bool
Enables the NewReference2 value to take effect
EnUpperLmt
IN
Bool
Enables the NewUpperLimit value to take effect
EnLowerLmt
IN
Bool
Enables the New_Lower_Limit value to take effect
EnOpMode
IN
Bool
Enables the NewOpModeBehavior value to take effect
EnLmtBehavior
IN
Bool
Enables the NewLimitBehavior value to take effect
EnSyncBehavior
IN
Bool
This value is not used.
NewDirection
IN
Int
Counting direction: 1 = count up; -1 = count down; all other
values are reserved.
NewOpModeBehavior
IN
Int
HSC’s operation on overflow: 1 = HSC stops counting (HSC
must be disabled and re-enabled to continue counting); 2 =
HSC continues to operate; all other values are reserved.
NewLimitBehavior
IN
Int
Result of the CurrentCount value on overflow: 1 = set CurrentCount to opposite limit; 2 = set CurrentCount to StartValue;
all other values are reserved.
NewSyncBehavior
IN
Int
This value is not used.
NewCurrentCount IN
Dint
CurrentCount Value
NewStartValue
IN
Dint
StartValue: Initial value of the HSC
NewReference1
IN
Dint
Reference1 Value
NewReference2
IN
Dint
Reference2 Value
NewUpperLimit
IN
Dint
Upper counting limit value
New_Lower_Limit IN
Dint
Lower counting limit value
S7-1200 Programmable controller
562
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
SDT: HSC_Period
The "HSC_Period" data type corresponds to an HSC configured for "Period" mode. The
CTRL_HSC_EXT instruction provides program access to the number of input pulses over a
specified measurement interval. This instruction allows for the time period between input
pulses to be calculated with a fine nanosecond resolution.
Table 10- 5
HSC_Period structure
Structure element Declaration
Data type
Description
ElapsedTime
OUT
UDInt
See description below.
EdgeCount
OUT
UDInt
See description below.
EnHSC
IN
Bool
Enables the HSC for Period measurement when true; disables
Period measurement when false.
EnPeriod
IN
Bool
Enables NewPeriod value to take effect.
NewPeriod
IN
Int
Specifies the measurement interval time in milliseconds. The
only allowed values are 10, 100 or 1000 ms.
ElapsedTime returns the time, in nanoseconds, between the last counting events of
sequential measurement intervals. If no counting events occurred during a measurement
interval, ElapsedTime returns the cumulative time since the last counting event.
ElapsedTime has a range from "0" to 4,294,967,280 nanoseconds (0x0000 0000 to 0xFFFF
FFF0). The return value 4,294,967,295 (0xFFFF FFFF) indicates that period overflow has
occurred. Overflow indicates that the time between pulse edges is greater than 4.295
seconds and the period cannot be calculated using this instruction. The values from 0xFFFF
FFF1 to 0xFFFF FFFE are reserved.
EdgeCount returns the number of counting events received during the measurement interval.
The period can only be calculated when the value of EdgeCount is greater than zero. If
ElapsedTime is either "0" (no input pulses received) or 0xFFFF FFFF (Period overflow), then
EdgeCount is not valid.
When EdgeCount is valid, use the following formula to calculate the period in nanoseconds:
Period = ElapsedTime/EdgeCount
The calculated time period value is an average of the time periods of all of the pulses that
occur during the measurement interval. If the period of an incoming pulse is greater than the
measurement interval (10, 100, or 1000 ms), then the period calculation requires multiple
measurement intervals.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
563
Technology instructions
10.1 Counting (High-speed counters)
The following examples show how the instruction makes period measurements:
S7-1200 Programmable controller
564
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
SDT: HSC_Frequency
The "HSC_Frequency" data type corresponds to an HSC configured for "Frequency" mode.
The instruction CTRL_HSC_EXT provides program access to the frequency of input pulses,
measured over a specified time period.
Using the CTRL_HSC_EXT instruction in Frequency mode provides the following
capabilities:
Table 10- 6
HSC_Frequency structure
Structure element Declaration
Data type
Description
Frequency
OUT
DInt
Returns a frequency in Hz, measured over the measurement
interval time. When the HSC counts down, the instruction
returns a negative frequency.
EnHSC
IN
Bool
Enables the HSC for Frequency measurement when true;
disables Frequency measurement when false.
EnPeriod
IN
Bool
Enables NewPeriod value to take effect.
NewPeriod
IN
Int
Specifies the measurement interval time in milliseconds. The
only allowed values are 10, 100, or 1000 ms.
The CTRL_HSC_EXT instruction measures the Frequency using the same measurement
technique as Period mode to find the ElapsedTime and EdgeCount. The instruction
calculates the frequency as a signed integer value in Hz using the formula: Frequency =
EdgeCount/ElapsedTime
If you require a floating-point value for frequency, you can use the above formula for
frequency when the HSC is in Period mode. Note that in Period mode, ElapsedTime is
returned in nanoseconds and can require scaling of the value.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
565
Technology instructions
10.1 Counting (High-speed counters)
10.1.2
Operating the high-speed counter
10.1.2.1
Synchronization function
You use the Sync (synchronization) function to set the counter to the start value with an
external input signal. You can modify the start value by executing the CTRL_HSC_EXT
instruction. This allows the user to synchronize the current count value to a desired value on
occurrence of an external input signal.
Synchronization always takes place at the occurrence of the input signal and is effective
regardless of the status of the internal gate. You must set the "HSC_Count.EnSync" bit to
true in order to enable the Sync function.
The CTRL_HSC_EXT instruction sets the HSC_Count.SyncActive status bit to true after
completion of synchronization. The CTRL_HSC_EXT instruction sets the
HSC_Count.SyncActive status bit to false if synchronization has not occurred since the last
instruction execution.
The figure below shows an example of synchronization when the input signal is configured
for an active high level:
Note
The configured input filters delay the control signal of the digital input.
This input function is only available to be used when the HSC is configured for Count mode.
S7-1200 Programmable controller
566
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
Refer to Input functions (Page 578) for information on how to configure the Synchronization
function.
10.1.2.2
Gate function
Many applications require counting processes to be started or stopped in accordance with
other events. In such cases, counting is started and stopped using the internal gate function.
Each HSC channel has two gates: a software gate and a hardware gate. The state of these
gates determines the state of the internal gate. See the table below.
The internal gate is open if the software gate is open and the hardware gate is open or has
not been configured. If the internal gate is open, counting is started. If the internal gate is
closed, all other count pulses are ignored and counting is stopped.
Table 10- 7
Gate function states
Hardware gate
Software gate
Internal gate
Open/not configured
Open
Open
Open/not configured
Closed
Closed
Closed
Open
Closed
Closed
Closed
Closed
The term "open" is defined to be the active state of the gate. Similarly, the term "closed" is defined to
be the inactive state of the gate.
You control the software gate with the "HSC_Count.EnHSC" enable bit in the SDT attached
to the CTRL_HSC_EXT instruction. To open the software gate, set the "HSC_Count.EnHSC"
bit true; to close the software gate, set the "HSC_Count.EnHSC" bit false. Execute the
CTRL_HSC_EXT instruction to update the software gate’s state.
The hardware gate is optional, and you can enable or disable it in the HSC properties
section. To control a counting process with only the hardware gate, the software gate must
remain open. If you do not configure a hardware gate, the hardware gate is considered to be
always open and the internal gate state is the same as the software gate state.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
567
Technology instructions
10.1 Counting (High-speed counters)
The figure below shows an example of the hardware gate opening and closing with a digital
input. The digital input is configured for an active high level:
Note
The configured input filters delay the control signal of the digital input.
The hardware gate function is only available to be used when the HSC is configured for
Count mode. In Period and Frequency modes, the internal gate state is the same as the
software gate state.
In Period mode, the software gate is controlled by "HSC_Period.EnHSC".
In Frequency mode, the software gate is controlled by "HSC_Frequency.EnHSC".
Refer to Input functions (Page 578) for information on how to configure the Gate function.
S7-1200 Programmable controller
568
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.2.3
Capture function
You use the Capture function to save the current counter value with an external reference
signal. When configured and enabled by the "HSC_Count.EnCapture" bit, the Capture
function causes the current count to be captured on the occurrence of an external input
edge. The Capture function is effective regardless of the status of the internal gate. The
program saves the unchanged counter value when the gate is closed. After executing the
CTRL_HSC_EXT instruction, the program stores the captured value in
"HSC_Count.CapturedCount".
The figure below shows an example of the Capture function configured to capture on a rising
edge. The Capture input does not trigger a capture of the current count when the
"HSC_Count.EnCapture" bit is set false through the CTRL_HSC_EXT instruction.
Note
The configured input filters delay the control signal of the digital input.
This input function can only be used when the HSC is configured for Count mode.
Refer to Input functions (Page 578) for information on how to configure the Capture function.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
569
Technology instructions
10.1 Counting (High-speed counters)
10.1.2.4
Compare function
When enabled, the Compare output function generates a single, configurable pulse that
occurs every time the configured event occurs. The events include count equal to one of the
reference values or the counter overflows. If a pulse is in progress and the event occurs
again, a pulse is not produced for that event.
Note
This output function can only be used when the HSC is configured for Count mode.
Refer to Output function (Page 579) for information on how to configure the Compare
function.
S7-1200 Programmable controller
570
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.2.5
Applications
A typical application uses the HSC to monitor feedback from an incremental shaft encoder.
The shaft encoder provides a specified number of counts per revolution that you can use as
the clock generator input to the HSC. There is also a reset pulse that occurs once per
revolution that you can use as the sync input to the HSC.
To start, the program loads the first reference value into the HSC and sets the outputs to
their initial states. The outputs remain in this state for the time period that the current count is
less than the reference value. The HSC provides an interrupt when the current count is equal
to the reference value, when the sync event (reset) occurs, and also when there is a
direction change.
As each counter value equals the reference value, an interrupt event occurs, and the
program loads a new reference value into the HSC and sets the outputs to their next state.
When the sync interrupt event occurs, the program sets the first reference value and the first
output states and repeats the cycle.
Since the interrupts occur at a much slower rate than the counting rate of the HSC, you can
implement precise control of high-speed operations with relatively minor impact to the scan
cycle of the CPU. The method of interrupt attachment allows each load of a new preset to be
performed in a separate interrupt routine for easy state control. Alternatively, you can
process all interrupt events in a single interrupt routine.
The Gate function, triggered either by the user program or an external input signal, can
disable counting of the encoder pulses. You can ignore any movement of the shaft by
deactivating the gate. This means that while the encoder continues to send pulses to the
HSC, the count value is held at the last value before the gate goes inactive. When the gate
goes active, counting resumes from the last value before the gate went inactive.
When enabled, the Capture function causes the current count to be captured on the
occurrence of an external input. A process (for example, a calibration routine) can use this
function to determine how many pulses occur between events.
When enabled, the Compare output function generates a single, configurable pulse that
occurs every time the current count reaches one of the reference values or overflows
(exceeds the counting limits). You can use this pulse as a signal to start another process
whenever a certain HSC event occurs.
The counting direction is controlled by either the user program or an external input signal.
To obtain the speed of the rotating shaft, you can configure the HSC for Frequency mode.
This function provides a signed integer value in units of Hz. Because the reset signal occurs
once per revolution, measuring the frequency of the reset signal provides a quick indication
of the shaft’s speed, in revolutions per second.
If you desire a floating point value of the frequency, configure the HSC for Period mode. You
can use the ElapsedTime and EdgeCount values returned in Period mode to calculate the
frequency.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
571
Technology instructions
10.1 Counting (High-speed counters)
10.1.3
Configuring a high-speed counter
To setup the high-speed counter (HSC):
● Select Device Configuration from the Project navigator.
● Select the CPU you wish to configure.
● Click the Properties tab, located in the Inspector window (see figure below).
● Select the HSC you want to enable from the list shown under the General tab (see figure
below).
You may configure up to six high-speed counters (HSC1 through HSC6). Enable an HSC by
selecting the "Enable this high speed counter" option. If enabled, STEP 7 assigns a unique
default name to this HSC. You can change this name by editing it in the "Name:" edit field;
however, it must be a unique name. Names of enabled HSCs become tags with the Data
type "HW_Hsc" in the "System constant" tag table and are available for use as the "HSC"
parameter of the CTRL_HSC_EXT instructions. Refer to "Configuring the operation of the
CPU (Page 170)" for further information:
After enabling the HSC, STEP 7 sets single phase counting as the default configuration.
Once you set the digital input filter for the HSC clock generator input, the program can be
downloaded to the PLC, and the CPU is ready to count. To change the HSC’s configuration,
proceed to the next section, "Type of Counting".
S7-1200 Programmable controller
572
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
The following table provides an overview of what inputs and outputs are available for each
configuration:
Table 10- 8
Type
Input 1
Input 2
Input 3
Input 4
Input 5
Output 1
Function
Single-phase
with internal
direction
control
Clock
-
-
-
-
-
Count, Frequency, or
Period
Sync
Gate
Capture
Compare
Count
Single-phase
with external
direction
control
Clock
-
-
-
-
Count, Frequency, or
Period
Sync
Gate
Capture
Compare
Count
Two-phase
Clock up
Clock down
-
-
-
-
Count, Frequency, or
Period
Sync
Gate
Capture
Compare
Count
A/B counter
Phase A
Phase B
-
-
-
-
Count, Frequency, or
Period
Sync1
Gate
Capture
Compare
Count
-
-
-
-
Count, Frequency, or
Period
Sync1
Gate
Capture
Compare
Count
A/B counter
fourfold
1
Counting modes for HSC
Phase A
Direction
Phase B
For an encoder: Phase Z, Home
10.1.3.1
Type of Counting
There are four types of counting or modes. When you change the mode, the available
configuration options for that HSC also change:
● Count: Counts the number of pulses and increments or decrements the count value,
depending on the state of the direction control. External I/O can reset the count, disable
counting, initiate a capture of the current count, and produce a single pulse on a specified
event. The output values are the current count value and the count value at the moment a
capture event occurs.
● Period: Counts the number of input pulses over a specified time period. Returns the pulse
count and time duration in nanoseconds (ns). Values are captured and calculated at the
end of the time period specified by Frequency measuring period.
● Frequency: Measures the input pulses and time duration and calculates the frequency of
the pulses. The program returns the frequency as a signed double integer in units of Hz.
The value is negative if the counting direction is down. Values are captured and
calculated at the end of the time period specified by the Frequency measuring period.
● Motion control: Used by the motion control technology object and not available to the
HSC instructions. Refer to "Motion control (Page 653)" for further information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
573
Technology instructions
10.1 Counting (High-speed counters)
10.1.3.2
Operating phase
Select the desired operating phase of the HSC. The four figures below show when the
counter value changes, when the current value (CV) equals the reference value (RV) event
occurs, and when the direction change event occurs.
Single phase
Single-phase (not available with motion control) counts pulses:
● User program (internal direction control):
– 1 is up
– -1 is down
● Hardware input (external direction control):
– High level is up.
– Low level is down.
S7-1200 Programmable controller
574
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
Two phase
Two phase counts:
● Up on the clock up input
● Down on the clock down input
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
575
Technology instructions
10.1 Counting (High-speed counters)
A/B counter
A/B phase quadrature counts:
● Up on the rising edge of the clock A input when the clock B input is low
● Down on the falling edge of the clock A input when the clock B input is low
S7-1200 Programmable controller
576
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
A/B counter fourfold
A/B phase quadrature fourfold counts:
● Up on the rising edge of the clock A input when the clock B input is low
● Up on the falling edge of the clock A input when the clock B input is high
● Up on the rising edge of the clock B input when the clock A input is high
● Up on the falling edge of the clock B input when the clock A input is low
● Down on the rising edge of the clock B input when the clock A input is low
● Down on the falling edge of the clock B input when the clock A input is high
● Down on the rising edge of the clock A input when the clock B input is high
● Down on the falling edge of the clock A input when the clock B input is low
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
577
Technology instructions
10.1 Counting (High-speed counters)
10.1.3.3
Initial values
Each time the CPU goes to RUN, it loads initial values. The initial values are only used in
count mode:
● Initial counter value: The program sets the current count value to the initial counter value
when the CPU goes from STOP to RUN mode or when the program triggers the sync
input.
● Initial reference value: When the current count reaches the reference value, if the
respective functions are set up, the program generates an interrupt and/or an output
pulse.
● Initial reference value 2: When the current count reaches the reference value 2, if the
function is set up, the program generates an output pulse.
● Initial upper limit value: Maximum counting value. The default is the largest possible value
of +2,147,483,647 pulses.
● Initial lower limit value: Minimum counting value. The default is the smallest possible
value of -2,147,483,648 pulses.
The values above and the behavior of the counter when it reaches a limit are only available
in Count mode. You can adjust the values and the behavior with the CTRL_HSC_EXT
instruction using the HSC_Count SDT.
10.1.3.4
Input functions
The Clock and direction inputs determine count events and direction, based upon the
operating phase. You can only use the Sync, Capture, and Gate inputs in Count mode and
can individually enable and configure the inputs for different types of triggers.
Synchronization input
The Sync (synchronization) input sets the current count value to the starting (or initial
counter) value. You typically use the Sync input to reset the counter to "0". You can trigger
the Sync when the input pin is in one of the following states:
● High
● Low
● Goes from low to high
● Goes from high to low
● Goes from high to low or from low to high
S7-1200 Programmable controller
578
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
Capture input
The Capture input sets the captured count value to the count value saved at the moment you
triggered the Capture input. You can trigger the capture when the input pin is in one of the
following states:
● Goes from low to high
● Goes from high to low
● Goes from high to low or from low to high
Gate input
The Gate input stops HSC counting. You can trigger the Gate when the input pin is in one of
the following states:
● High
● Low
10.1.3.5
Output function
The compare output function is the only output for the HSC and is only available in Count
mode.
Compare output
You can configure the Compare output to generate a single pulse on the occurrence of one
of the following events:
● Counter equals reference value (count direction is up)
● Counter equals reference value (count direction is down)
● Counter equals reference value (count direction is up or down)
● Counter equals reference value 2 (count direction is up)
● Counter equals reference value 2 (count direction is down)
● Counter equals reference value 2 (count direction is up or down)
● Positive overflow
● Negative overflow
You can configure the output pulse with a cycle time ranging from 1 to 500 ms; the default
cycle time is 10 ms. You can set the pulse width, or duty cycle, anywhere from 1 to 100%;
the default pulse width is 50%.
If multiple compare output events occur within the specified cycle time, the output pulses
from those events are lost due to the fact that the current pulse has not completed its cycle
yet. Once the pulse has finished (the configured cycle time has passed), the pulse generator
is available to produce a new pulse.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
579
Technology instructions
10.1 Counting (High-speed counters)
10.1.3.6
Interrupt events
Under the Event configuration section, you can select a hardware interrupt OB from the
dropdown menu (or you can create a new OB) and attach it to an HSC event. The priority of
the interrupt is in a range from 2 to 26, where 2 is the lowest priority and 26 is the highest
priority. Depending on the HSC’s configuration, the following events are available:
● Counter value equals reference value event: A counter value equals reference value
event occurs when the HSC’s count value reaches the reference value. You can set the
reference value during configuration under the Initial reference value section, or by
updating "NewReference1" using the CTRL_HSC_EXT instruction. Refer to the
"Operating phase (Page 574)" section for further information.
● Synchronization event: A Sync (synchronization) occurs whenever you enable and trigger
the Sync input.
● Change of direction event: A change of direction event occurs when the counting
direction changes. Refer to the "Operating phase (Page 574)" section for further
information.
10.1.3.7
Hardware input pin assignment
For each HSC input that you enable, select the desired input point, located either on the
CPU or optional signal board (communication and signal modules do not support HSC
inputs). When you select a point, STEP 7 displays the maximum frequency value next to the
selection. The digital input filter settings may need to be adjusted so that all valid signal
frequencies can pass through the filter. To set up the HSC input filters, refer to "Configuring
digital input filter times (Page 172)".
Note
CPU and SB input channels (V4 or later firmware) have configurable input filter times
Earlier firmware versions had fixed HSC input channels and fixed filter times that you could
not change.
With V4 or later versions, you can assign input channels and filter times. The default input
filter setting is 6.4 ms, which limits the maximum counting rate to 78 Hz. You can change the
filter settings to count higher or lower frequencies depending on the design of your system.
WARNING
Risks with changes to filter time setting for digital input channels
If the filter time for a digital input channel is changed from a previous setting, a new "0"
level input value might need to be presented for up to a 20.0 ms accumulated duration
before the filter becomes fully responsive to new inputs. During this time, short "0" pulse
events of duration less than 20.0 ms may not be detected or counted.
The changing of filter times can result in unexpected machine or process operation, which
can cause death or serious injury to personnel, and/or damage to equipment.
To ensure that a new filter time goes immediately into effect, power cycle the CPU.
S7-1200 Programmable controller
580
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
Use the following table and ensure that the CPU and SB input channels that you connect
can support the maximum pulse rates in your process signals:
Table 10- 9
CPU input: maximum frequency
CPU
CPU Input channel
Operating phase: Single
phase or Two phase
Operating phase: A/B
counter or A/B Counter
fourfold
1211C
Ia.0 to Ia.5
100 kHz
80 kHz
1212C
1214C and 1215C
1217C
Ia.0 to Ia.5
100 kHz
80 kHz
Ia.6, Ia.7
30 kHz
20 kHz
Ia.0 to Ia.5
100kHz
80kHz
Ia.6 to Ib.5
30 kHz
20 kHz
Ia.0 to Ia.5
100 kHz
80 kHz
Ia.6 to Ib.1
30 kHz
20 kHz
Ib.2 to Ib.5
1 MHz
1 MHz
(.2+, .2- to .5+, .5-)
Table 10- 10 SB signal board input: maximum frequency (optional board)
SB signal board
SB input channel
Operating phase: Single
phase or Two phase
Operating phase: A/B
counter or A/B Counter
fourfold
SB 1221, 200 kHz
Ie.0 to Ie.3
200kHz
160 kHz
SB 1223, 200 kHz
Ie.0, Ie.1
200kHz
160 kHz
SB 1223
Ie.0, Ie.1
30 kHz
20 kHz
When assigning an input point to an HSC function, you can assign the same input point to
multiple HSC functions. For example, assigning I0.3 to the Sync input of HSC1 and the Sync
input of HSC2 to synchronize the count of both HSCs at the same time is a valid
configuration; however, it generates a compiler warning.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
581
Technology instructions
10.1 Counting (High-speed counters)
When possible, avoid assigning multiple input functions of the same HSC to the same input
point. For example, assigning I0.3 to the Sync input and the Gate input of HSC 1 to
synchronize the count and disable counting at the same time is also a valid configuration.
You can make this configuration, but it could produce unintended results. Refer to the
Warning below for further information.
WARNING
Risks with assigning multiple functions to a single digital input channel
Assigning multiple input functions of the same HSC to a common input point may produce
unpredictable results. When a trigger occurs on a point with multiple functions assigned to
that trigger, the order in which the functions are executed by the PLC cannot be known.
This is known as a race condition and is often an undesirable situation.
This race condition can result in unexpected machine or process operation, which can
cause death or serious injury to personnel, and/or damage to equipment.
To avoid a race condition, do not assign more than two input functions, of the same HSC,
to the same input pin. If an HSC has two input functions assigned to the same pin, set the
triggers such that they could never occur at the same time. Remember that a falling edge
occurs at the same instance that a low level begins and that a rising edge occurs at the
same instance that a high level begins.
Note
You assign the digital input and output points used by high-speed counter (HSC) devices
during CPU device configuration. When you assign input and output points to HSC devices,
you cannot modify the values of these points using the force function in a watch table. The
HSC has full control of these input and output points.
10.1.3.8
Hardware output pin assignment
If you enable the Compare output, select an available output point. Once you configure an
output point for use by an HSC (or other technology objects such as a pulse generator), that
output point is owned exclusively by that object. No other component can use the output
point, and the output point cannot be forced to a value. If you configure a single output
channel for multiple HSCs or for use in an HSC and a pulse output, the program generates a
compile error.
S7-1200 Programmable controller
582
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.3.9
HSC input memory addresses
Each HSC uses a double word section of I-memory that stores the current count. If you
configure the HSC for frequency, then the frequency is stored in that input memory location.
The available input address range is I0.0 to I1023.7 (maximum start address is I1020.0). The
HSC cannot use an input address that overlaps with an input address mapped to another
component. For further information on the process image, refer to "Execution of the user
program (Page 83)".
The following table shows the default addresses assigned for each HSC:
Table 10- 11 HSC default addresses
10.1.3.10
High-speed counter (HSC)
Current value data type
Default current value address
HSC1
DInt
ID 1000
HSC2
DInt
ID 1004
HSC3
DInt
ID 1008
HSC4
DInt
ID 1012
HSC5
DInt
ID 1016
HSC6
DInt
ID 1020
Hardware identifier
Each HSC has a unique hardware identifier, which is used by the HSC_CTRL and
HSC_CTRL_EXT instructions. You can find the PLC tag for the hardware identifier under
"System Constants". An HSC with the name "HSC_1" has the tag "Local~HSC_1" and data
type "Hw_Hsc". This tag is also shown in the dropdown menu when selecting the HSC input
of the CTRL_HSC_EXT instructions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
583
Technology instructions
10.1 Counting (High-speed counters)
10.1.4
Legacy CTRL_HSC (Control high-speed counter) instruction
10.1.4.1
Instruction overview
Table 10- 12 CTRL_HSC instruction (For general purpose counting)
LAD / FBD
SCL
"CTRL_HSC_1_DB" (
hsc:=W#16#0,
dir:=False,
cv:=False,
rv:=False,
period:=False,
new_dir:=0,
new_cv:=L#0,
new_rv:=L#0,
new_period:=0,
busy=>_bool_out_,
status=>_word_out_);
Description
Each CTRL_HSC (Control high-speed
counter) instruction uses a structure
stored in a DB to maintain counter data.
You assign the DB when the CTRL_HSC
instruction is placed in the editor.
1
When you insert the instruction, STEP 7 displays the "Call Options" dialog for creating the associated DB.
2
In the SCL example, "CTRL_HSC_1_DB" is the name of the instance DB.
S7-1200 Programmable controller
584
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
Table 10- 13 Data types for the parameters
Parameter
Declaration
Data type
Description
HSC
IN
HW_HSC
HSC identifier
DIR1, 2
IN
Bool
1 = Request new direction
CV1
IN
Bool
1 = Request to set new counter value
RV1
IN
Bool
1= Request to set new reference value
PERIOD1
IN
Bool
1 = Request to set new period value
(only for frequency measurement mode)
NEW_DIR
IN
Int
New direction: 1= forward, -1= backward
NEW_CV
IN
DInt
New counter value
NEW_RV
IN
DInt
New reference value
NEW_PERIOD
IN
Int
New period value is in milliseconds (only for frequency measurement mode). The only allowed values are 10, 100, or 1000
milliseconds:
1000 = 1 second
100 = 0.1 second
10 = 0.01 second
BUSY3
OUT
Bool
Function is busy
STATUS
OUT
Word
Execution condition code
1
If an update of a parameter value is not requested, then the corresponding input values are ignored.
2
The DIR parameter is only valid if the configured counting direction is set to "User program (internal direction control)".
You determine how to use this parameter in the HSC device configuration.
3
For an HSC on the CPU or on the SB, the BUSY parameter always has a value of 0.
You configure the parameters for each HSC in the device configuration for the CPU for
counting/frequency function, reset options, interrupt event configuration, hardware I/O, and
count value address.
Some of the parameters for the HSC can be modified by your user program to provide
program control of the counting process:
● Set the counting direction to a NEW_DIR value
● Set the current count value to a NEW_CV value
● Set the reference value to a NEW_RV value
● Set the period value (for frequency measurement mode) to a NEW_PERIOD value
If the following Boolean flag values are set to 1 when the CTRL_HSC instruction is executed,
the corresponding NEW_xxx value is loaded to the counter. Multiple requests (more than
one flag is set at the same time) are processed in a single execution of the CTRL_HSC
instruction.
● DIR = 1 is a request to load a NEW_DIR value, 0 = no change
● CV = 1 is a request to load a NEW_CV value, 0 = no change
● RV = 1 is a request to load a NEW_RV value, 0 = no change
● PERIOD = 1 is a request to load a NEW_PERIOD value, 0 = no change
If an error occurs, ENO is set to "0" and the STATUS output indicates a condition code:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
585
Technology instructions
10.1 Counting (High-speed counters)
Table 10- 14 Execution condition codes
STATUS (W#16#)
10.1.4.2
Description
0
No error
80A1
HSC identifier does not address a HSC
80B1
Illegal value in NEW_DIR
80B2
Illegal value in NEW_CV
80B3
Illegal value in NEW_RV
80B4
Illegal value in NEW_PERIOD
80C0
Multiple access to the high-speed counter
80D0
High-speed counter (HSC) not enabled in CPU hardware configuration
Using CTRL_HSC
The CTRL_HSC instruction is typically placed in a hardware interrupt OB that is executed
when the counter hardware interrupt event is triggered. For example, if a CV=RV event
triggers the counter interrupt, then a hardware interrupt OB code block executes the
CTRL_HSC instruction and can change the reference value by loading a NEW_RV value.
The current count value is not available in the CTRL_HSC parameters. The process image
address that stores the current count value is assigned during the hardware configuration of
the high-speed counter. You may use program logic to directly read the count value. The
value returned to your program will be a correct count for the instant in which the counter
was read. The counter will continue to count high-speed events. Therefore, the actual count
value could change before your program completes a process using an old count value.
S7-1200 Programmable controller
586
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.1 Counting (High-speed counters)
10.1.4.3
HSC current count value
The CPU stores the current value of each HSC in an input (I) address. The following table
shows the default addresses assigned to the current value for each HSC. You can change
the I address for the current value by modifying the properties of the CPU in the Device
Configuration.
High-speed counters use a DInt value to store the current count value. A DInt count value
has a range of -2147483648 to +2147483647. As of CPU firmware V4.2, you can configure
the range limits. Refer to "Initial values (Page 578)" for further information.
The counter rolls over from the maximum positive value to the maximum negative value
when counting up, and from the maximum negative value to the maximum positive value
when counting down. Frequency is returned in units of Hertz (for example, 123.4 Hz is
returned as 123).
Table 10- 15 HSC default addresses
HSC
Current value data type
Default current value address
HSC1
DInt
ID1000
HSC2
DInt
ID1004
HSC3
DInt
ID1008
HSC4
DInt
ID1012
HSC5
DInt
ID1016
HSC6
DInt
ID1020
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
587
Technology instructions
10.2 PID control
10.2
PID control
STEP 7 provides the following PID instructions for the S7-1200 CPU:
● The PID_Compact instruction is used to control technical processes with continuous
input- and output variables.
● The PID_3Step instruction is used to control motor-actuated devices, such as valves that
require discrete signals for open- and close actuation.
● The PID_Temp instruction provides a universal PID controller that allows handling of the
specific requirements of temperature control.
Note
Changes that you make to the PID configuration and download in RUN do not take effect
until the CPU transitions from STOP to RUN mode. Changes that you make in the "PID
parameters" dialog using the "Start value control" take effect immediately.
All three PID instructions (PID_Compact, PID_3Step, and PID_Temp) can calculate the P-, I, and D-components during startup (if configured for "pre-tuning"). You can also configure
the instruction for "fine tuning" to allow you to optimize the parameters. You do not need to
manually determine the parameters.
Note
Execute the PID instruction at constant intervals of the sampling time (preferably in a cyclic
OB).
Because the PID loop needs a certain time to respond to changes of the control value, do
not calculate the output value in every cycle. Do not execute the PID instruction in the main
program cycle OB (such as OB 1).
The sampling time of the PID algorithm represents the time between two calculations of the
output value (control value). The output value is calculated during self-tuning and rounded to
a multiple of the cycle time. All other functions of PID instruction are executed at every call.
S7-1200 Programmable controller
588
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
PID algorithm
The PID (Proportional/Integral/Derivative) controller measures the time interval between two
calls and then evaluates the results for monitoring the sampling time. A mean value of the
sampling time is generated at each mode changeover and during initial startup. This value is
used as reference for the monitoring function and is used for calculation. Monitoring includes
the current measuring time between two calls and the mean value of the defined controller
sampling time.
The output value for the PID controller consists of three components:
● P (proportional): When calculated with the "P" component, the output value is proportional
to the difference between the setpoint and the process value (input value).
● I (integral): When calculated with the "I" component, the output value increases in
proportion to the duration of the difference between the setpoint and the process value
(input value) to finally correct the difference.
● D (derivative): When calculated with the "D" component, the output value increases as a
function of the increasing rate of change of the difference between the setpoint and the
process value (input value). The output value is corrected to the setpoint as quickly as
possible.
The PID controller uses the following formula to calculate the output value for the
PID_Compact instruction.
y
Output value
x
Process value
w
Setpoint value
s
Laplace operator
Kp
Proportional gain
(P component)
a
Derivative delay coefficient
(D component)
T1
Integral action time
(I component)
b
Proportional action weighting
(P component)
TD
Derivative action time
(D component)
c
Derivative action weighting
(D component)
The PID controller uses the following formula to calculate the output value for the PID_3Step
instruction.
y
Output value
x
Process value
w
Setpoint value
s
Laplace operator
Kp
Proportional gain
(P component)
a
Derivative delay coefficient
(D component)
T1
Integral action time
(I component)
b
Proportional action weighting
(P component)
TD
Derivative action time
(D component)
c
Derivative action weighting
(D component)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
589
Technology instructions
10.2 PID control
10.2.1
Inserting the PID instruction and technology object
STEP 7 provides two instructions for PID control:
● The PID_Compact instruction and its associated technology object provide a universal
PID controller with tuning. The technology object contains all of the settings for the control
loop.
● The PID_3Step instruction and its associated technology object provide a PID controller
with specific settings for motor-activated valves. The technology object contains all of the
settings for the control loop. The PID_3Step controller provides two additional Boolean
outputs.
After creating the technology object, you must configure the parameters (Page 622). You
also adjust the autotuning parameters ("pre-tuning" during startup or manual "fine tuning") to
commission the operation of the PID controller (Page 640).
Table 10- 16 Inserting the PID instruction and the technology object
When you insert a PID instruction into your user program,
STEP 7 automatically creates a technology object and an
instance DB for the instruction. The instance DB contains
all of the parameters that are used by the PID instruction.
Each PID instruction must have its own unique instance
DB to operate properly.
After inserting the PID instruction and creating the technology object and instance DB, you configure the parameters for the technology object (Page 622).
S7-1200 Programmable controller
590
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Table 10- 17 (Optional) Creating a technology object from the project navigator
You can also create technology objects for your
project before inserting the PID instruction. By
creating the technology object before inserting a
PID instruction into your user program, you can
then select the technology object when you insert
the PID instruction.
To create a technology object, double-click the
"Add new object" icon in the project navigator.
Click the "Control" icon and select the technology
object for the type of PID controller (PID_Compact
or PID_3Step). You can create an optional name
for the technology object.
Click "OK" to create the technology object.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
591
Technology instructions
10.2 PID control
10.2.2
PID_Compact
10.2.2.1
PID_Compact instruction
The PID_Compact instruction provides a universal PID controller with integrated self-tuning
for automatic and manual mode.
Table 10- 18 PID_Compact instruction
LAD / FBD
SCL
"PID_Compact_1"(
Setpoint:=_real_in_,
Input:=_real_in_,
Input_PER:=_word_in_,
Disturbance:=_real_in_,
ManualEnable:=_bool_in_,
ManualValue:=_real_in_,
ErrorAck:=_bool_in_,
Reset:=_bool_in_,
ModeActivate:=_bool_in_,
Mode:=_int_in_,
ScaledInput=>_real_out_,
Output=>_real_out_,
Output_PER=>_word_out_,
Output_PWM=>_bool_out_,
SetpointLimit_H=>_bool_out_,
SetpointLimit_L=>_bool_out_,
InputWarning_H=>_bool_out_,
InputWarning_L=>_bool_out_,
State=>_int_out_,
Error=>_bool_out_,
ErrorBits=>_dword_out_);
Description
PID_Compact provides a PID controller with
self-tuning for automatic and manual mode.
PID_Compact is a PID T1 controller with
anti-windup and weighting of the P- and Dcomponent.
1
STEP 7 automatically creates the technology object and instance DB when you insert the instruction. The instance DB
contains the parameters of the technology object.
2
In the SCL example, "PID_Compact_1" is the name of the instance DB.
S7-1200 Programmable controller
592
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Table 10- 19 Data types for the parameters
Parameter and type
Data type
Description
Setpoint
IN
Real
Setpoint of the PID controller in automatic mode. (Default value: 0.0)
Input
IN
Real
A tag of the user program is used as the source of the process value.
(Default value: 0.0)
If you are using the Input parameter, you must set Config.InputPerOn = FALSE.
Input_PER
IN
Word
An Analog input is used as the source of the process value. (Default
value: W#16#0)
If you are using the Input_PER parameter, you must set Config.InputPerOn = TRUE.
Disturbance
IN
Real
Disturbance variable or pre-control value
ManualEnable
IN
Bool
Enables or disables the manual operation mode. (Default value:
FALSE):
•
A FALSE to TRUE edge activates "manual mode", while State = 4,
Mode remains unchanged.
As long as ManualEnable = TRUE, you cannot change the operating mode using a rising edge at ModeActivate or use the commissioning dialog.
A TRUE to FALSE edge activates the operating mode that is assigned by Mode.
Note: We recommend that you change the operating mode using
ModeActivate only.
•
ManualValue
IN
Real
Output value for manual operation. (Default value: 0.0)
You can use values from Config.OutputLowerLimit to Config.OutputUpperLimit.
ErrorAck
IN
Bool
Resets the ErrorBits and warning outputs. FALSE to TRUE edge
Reset
IN
Bool
Restarts the controller. (Default value: FALSE):
•
FALSE to TRUE edge:
–
Switches to "inactive" mode
–
Resets the ErrorBits and warning outputs
–
Clears Integral action
–
Maintains PID parameters
•
As long as Reset = TRUE, PID_Compact remains in "Inactive"
mode (State = 0).
•
TRUE to FALSE edge:
–
PID_Compact switches to the operating mode that is saved in
the Mode parameter.
ModeActivate
IN
Bool
The PID_Compact switches to the operating mode that is saved in the
Mode parameter. FALSE to TRUE edge:
Mode
IN
Int
The desired PID mode; Activated on the leading edge of the Mode
Activate input.
ScaledInput
OUT
Real
Scaled process value. (Default value: 0.0)
Output1
OUT
Real
Output value in REAL format. (Default value: 0.0)
Output_PER1
OUT
Word
Analog output value. (Default value: W#16#0)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
593
Technology instructions
10.2 PID control
Parameter and type
Data type
Description
Output_PWM1
OUT
Bool
Output value for pulse width modulation. (Default value: FALSE)
SetpointLimit_H
OUT
Bool
On and Off times form the output value.
Setpoint high limit. (Default value: FALSE)
If SetpointLimit_H = TRUE, the absolute setpoint upper limit is reached
(Setpoint ≥ Config.SetpointUpperLimit).
The setpoint is limited to Config.SetpointUpperLimit.
SetpointLimit_L
OUT
Bool
Setpoint low limit. (Default value: FALSE)
If SetpointLimit_L = TRUE, the absolute setpoint lower limit is reached
(Setpoint ≤ Config.SetpointLowerLimit).
The setpoint is limited to Config.SetpointLowerLimit.
InputWarning_H
OUT
Bool
If InputWarning_H = TRUE, the process value has reached or exceeded the warning high limit. (Default value: FALSE)
InputWarning_L
OUT
Bool
If InputWarning_L = TRUE, the process value has reached or fallen
below the warning low limit. (Default value: FALSE)
State
OUT
Int
Current operating mode of the PID controller. (Default value: 0)
You can change the operating mode using the Mode input parameter
and a rising edge at ModeActivate:
Error
OUT
Bool
•
State = 0: Inactive
•
State = 1: Pre-tuning
•
State = 2: Manual fine tuning
•
State = 3: Automatic mode
•
State = 4: Manual mode
•
State = 5: Substitute output value with error monitoring
If Error = TRUE, at least one error message is pending in this cycle.
(Default value: FALSE)
Note: The Error parameter in V1.x PID was the ErrorBits field that contained the error codes. It is now a Boolean flag indicating that an error
has occurred.
ErrorBits
OUT
DWord
The PID_Compact instruction ErrorBits parameters table (Page 597)
defines the error messages that are pending. (Default value:
DW#16#0000 (no error)). ErrorBits is retentive and is reset upon a
rising edge at Reset or ErrorAck.
Note: In V1.x, the ErrorBits parameter was defined as the Error parameter and did not exist.
1
You can use the outputs of the Output, Output_PER, and Output_PWM parameters in parallel.
S7-1200 Programmable controller
594
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Operation of the PID_Compact controller
Figure 10-1
Operation of the PID_Compact controller
Figure 10-2
Operation of the PID_Compact controller as a PIDT1 controller with anti-windup
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
595
Technology instructions
10.2 PID control
10.2.2.2
PID_Compact instruction Process value limits
"Process value limits" are normally used in conjunction with the analog input; however, you
can use them for other purposes.
The Process value limits configuration serves two functions:
● Sets the upper and lower limits for the Setpoint High/Low alarm outputs on the PID block
● Sets a limit so that the process variable cannot exceed or go below those limits
regardless of the setpoint. This configuration defines fixed limits for the process.
On the PID block, you can use four alarm outputs:
● SetpointLimit_H: Setpoint exceeds the High Limit.
● SetpointLimit_L: Setpoint exceeds the Low Limit.
● InputWarning_H: Process Variable exceeds the input high limit.
● InputWarning_L: Process Variable exceeds the input low limit.
When you set the Process value limits, the points that trigger the Setpoint high and low
alarm outputs to go true are set to the same value. For example, with the settings shown
above, if you enter a setpoint that is greater than 120%, the "SetpointLimit_H" output goes
true. This action is the same for the low limit. If you enter a setpoint that is lower than 0%,
then the "SetpointLimit_L" goes true. This gives your program an indication that the entered
setpoint is out-of-range. This alarm can prompt you to re-enter the setpoint.
S7-1200 Programmable controller
596
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
If you enter a setpoint that is out-of-range, the Compact_PID automatically limits the process
variable to the configured range. For example, if the Process value high limit is set to 120%
(as shown in the figure above), you can still enter a setpoint higher than 120%. As the
process variable approaches 120%, the PID reduces the output and controls the process at
the high limit of 120%. Conversely, the same action occurs if the setpoint is lower than the
Process value low limit. The PID does not let the process variable go below the low limit.
This feature allows you to define the acceptable process operation during normal automatic
PID control. However, this feature does not apply to startup and shutdown unless the PID is
in automatic mode. If the PID is in automatic mode and the setpoint and process variable are
less than the lower limit, the PID tries to control the process at the configured lower limit.
10.2.2.3
PID_Compact instruction ErrorBit parameters
If several errors are pending, the values of the error codes are displayed by means of binary
addition. The display of error code 0003, for example, indicates that the errors 0001 and
0002 are also pending.
Table 10- 20 PID_Compact instruction ErrorBit parameters
ErrorBit (DW#16#...)
Description
0000
No error
0001 1, 2
The Input parameter is outside the process value limits.
Input > Config.InputUpperLimit
Input < Config.InputLowerLimit
0002
2, 3
Invalid value at the Input_PER parameter. Check whether an error is pending at the analog input.
0004 4
Error during fine tuning. Oscillation of the process value could not be maintained.
0008 4
Error at start of pre-tuning. The process value is too close to the setpoint.
Start fine tuning.
0010 4
The setpoint was changed during tuning.
Note: You can set the permitted fluctuation on the setpoint at the CancelTuningLevel tag.
0020
Pre-tuning is not permitted during fine tuning.
Note: If ActivateRecoverMode = TRUE before the error occurred,
PID_Compact remains in fine tuning mode.
0080 4
Error during pre-tuning. Incorrect configuration of output value limits.
Check whether the limits of the output value are configured correctly and
match the control logic.
0100 4
Error during fine tuning resulted in invalid parameters.
0200 2, 3
Invalid value at the Input parameter: Value has an invalid number format.
0400
2, 3
Calculation of the output value failed. Check the PID parameters.
0800
1, 2
Sampling time error: PID_Compact is not called within the sampling time of
the cyclic interrupt OB.
1000 2, 3
Invalid value at the Setpoint parameter: Value has an invalid number format.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
597
Technology instructions
10.2 PID control
ErrorBit (DW#16#...)
Description
10000
Invalid value at the ManualValue parameter: Value has an invalid number
format.
Note: If ActivateRecoverMode = TRUE before the error occurred,
PID_Compact uses SubstituteOutput as the output value. As soon as you
assign a valid value in the ManualValue parameter, PID_Compact uses it as
the output value.
20000
Invalid value at the SubstituteValue tag: Value has an invalid number format.
PID_Compact uses the output value low limit as the output value.
Note: If automatic mode was active before the error occurred, ActivateRecoverMode = TRUE, and the error is no longer pending,
PID_Compact switches back to automatic mode.
40000
Invalid value at the Disturbance parameter: Value has an invalid number
format.
Note: If automatic mode was active and ActivateRecoverMode = FALSE
before the error occurred, Disturbance is set to zero. PID_Compact remains
in automatic mode.
Note: If pre-tuning or fine tuning mode was active and ActivateRecoverMode
= TRUE before the error occurred, PID_Compact switches to the operating
mode that is saved in the Mode parameter. If Disturbance in the current
phase has no effect on the output value, tuning is not canceled.
1
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_Compact remains in automatic mode.
2
Note: If pre-tuning or fine tuning mode was active before the error occurred and ActivateRecoverMode = TRUE, PID_Compact switches to the operating mode that is saved in the
Mode parameter.
3
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_Compact outputs the configured substitute output value. As soon as the error is no longer
pending, PID_Compact switches back to automatic mode.
4
Note: If ActivateRecoverMode = TRUE before the error occurred, PID_Compact cancels the tuning
and switches to the operating mode that is saved in the Mode parameter.
S7-1200 Programmable controller
598
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
10.2.2.4
PID_Compact instruction Warning parameters
If the PID controller has several warnings pending, it displays the values of the error codes
by means of binary addition. The display of error code 0003, for example, indicates that the
errors 0001 and 0002 are pending.
Table 10- 21 PID_Compact instruction Warning parameters
Warning (DW#16#...)
Description
0000
No warning pending.
0001 1
The point of inflection was not found during pretuning.
0002
Oscillation was enforced during “tuning in run”. (The "Warning" parameter suppresses this
warning and is only visible in the “WarningInternal” parameter for diagnostic purposes.)
0004 1
The setpoint was limited to the configured limits.
0008
Not all the necessary controlled system properties were defined for the selected method of
calculation. Instead, the PID parameters were calculated using the TIR.TuneRuleHeat /
TIR.TuneRuleCool = 3 method.
0010
The operating mode could not be changed because Reset = TRUE or ManualEnable =
TRUE.
0020
The cycle time of the calling OB limits the sampling time of the PID algorithm. Improve results by using shorter OB cycle times.
0040 1
The process value exceeded one of its warning limits.
0080
Invalid value at Mode. The operating mode is not switched.
0100
1
1
1
The manual value was limited to the limits of the controller output.
0200
The specified rule for tuning is not supported. No PID parameters are calculated.
1000
The substitute output value cannot be reached because it is outside the output value limits.
Note: The PID controller deleted the following warnings automatically as soon as the cause is eliminated or the user
action repeated with valid parameters: 0001, 0004, 0008, 0040, and 0100.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
599
Technology instructions
10.2 PID control
10.2.3
PID_3Step
10.2.3.1
PID_3Step instruction
The PID_3Step instruction configures a PID controller with self-tuning capabilities that has
been optimized for motor-controlled valves and actuators.
Table 10- 22 PID_3Step instruction
LAD / FBD
SCL
"PID_3Step_1"(
SetpoInt:=_real_in_,
Input:=_real_in_,
ManualValue:=_real_in_,
Feedback:=_real_in_,
InputPer:=_word_in_,
FeedbackPer:=_word_in_,
Disturbance:=_real_in_,
ManualEnable:=_bool_in_,
ManualUP:=_bool_in_,
ManualDN:=_bool_in_,
ActuatorH:=_bool_in_,
ActuatorL:=_bool_in_,
ErrorAck:=_bool_in_,
Reset:=_bool_in_,
ModeActivate:=_bool_in_,
Mode:=_int_in_,
ScaledInput=>_real_out_,
ScaledFeedback=>_real_out_,
ErrorBits=>_dword_out_,
OutputPer=>_word_out_,
State=>_int_out_,
OutputUP=>_bool_out_,
OutputDN=>_bool_out_,
SetpoIntLimitH=>_bool_out_,
SetpoIntLimitL=>_bool_out_,
InputWarningH=>_bool_out_,
InputWarningL=>_bool_out_,
Error=>_bool_out_,
ErrorBits=>_dword_out_);
Description
PID_3Step configures a PID controller with
self-tuning capabilities that has been optimized for motor-controlled valves and
actuators. It provides two Boolean outputs.
PID_3Step is a PID T1controller with antiwindup and weighting of the P- and Dcomponents.
1
STEP 7 automatically creates the technology object and instance DB when you insert the instruction. The instance DB
contains the parameters of the technology object.
2
In the SCL example, "PID_3Step_1" is the name of the instance DB.
S7-1200 Programmable controller
600
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Table 10- 23 Data types for the parameters
Parameter and type
Data type
Description
Setpoint
IN
Real
Setpoint of the PID controller in automatic mode. (Default value: 0.0)
Input
IN
Real
A tag of the user program is used as the source of the process value.
(Default value: 0.0)
If you are using the Input parameter, you must set Config.InputPerOn = FALSE.
Input_PER
IN
Word
An Analog input is used as the source of the process value. (Default
value: W#16#0)
If you are using the Input_PER parameter, you must set Config.InputPerOn = TRUE.
Actuator_H
IN
Bool
Digital position feedback of the valve for the high end stop
If Actuator_H = TRUE, the valve is at the high end stop and is no longer
moved in this direction. (Default value: FALSE)
Actuator_L
IN
Bool
Digital position feedback of the valve for the low end stop
If Actuator_L = TRUE, the valve is at the low end stop and is no longer
moved in this direction. (Default value: FALSE)
Feedback
IN
Real
Position feedback of the valve. (Default value: 0.0)
If you are using the Feedback parameter, you must set Config.FeedbackPerOn = FALSE.
Feedback_PER
IN
Int
Analog feedback of the valve position. (Default value: W#16#0)
If you are using the Feedback_PER parameter, you must set Config.FeedbackPerOn = TRUE. Feedback_PER is scaled, based upon the
following tags:
•
Config.FeedbackScaling.LowerPointIn
•
Config.FeedbackScaling.UpperPointIn
•
Config.FeedbackScaling.LowerPointOut
•
Config.FeedbackScaling.UpperPointOut
Disturbance
IN
Real
Disturbance variable or pre-control value
ManualEnable
IN
Bool
Enables or disables the manual operation mode. (Default value:
FALSE):
•
A FALSE to TRUE edge activates "manual mode", while State = 4,
Mode remains unchanged.
As long as ManualEnable = TRUE, you cannot change the operating mode using a rising edge at ModeActivate or use the commissioning dialog.
A TRUE to FALSE edge activates the operating mode that is assigned by Mode.
Note: We recommend that you change the operating mode using
ModeActivate only.
•
ManualValue
IN
Real
Process value for manual operation. (Default value: 0.0)
In manual mode, you specify the absolute position of the valve. ManualValue is evaluated only if you are using OutputPer, or if position feedback is available.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
601
Technology instructions
10.2 PID control
Parameter and type
ManualUP
IN
Data type
Description
Bool
•
•
Manual_UP = TRUE:
–
The valve is opened even if you use Output_PER or a position
feedback. The valve is no longer moved if the high end stop has
been reached.
–
See also Config.VirtualActuatorLimit
Manual_UP = FALSE:
–
If you use Output_PER or a position feedback, the valve is
moved to ManualValue. Otherwise, the valve is no longer
moved.
Note: If Manual_UP and Manual_DN are set to TRUE simultaneously,
the valve is not moved.
ManualDN
IN
Bool
•
•
Manual_DN = TRUE:
–
The valve is opened even if you use Output_PER or a position
feedback. The valve is no longer moved if the high end stop has
been reached.
–
See also Config.VirtualActuatorLimit
Manual_DN = FALSE:
–
If you use Output_PER or a position feedback, the valve is
moved to ManualValue. Otherwise, the valve is no longer
moved.
ErrorAck
IN
Bool
Resets the ErrorBits and warning outputs. FALSE to TRUE edge
Reset
IN
Bool
Restarts the controller. (Default value: FALSE):
•
FALSE to TRUE edge:
–
Switches to "inactive" mode
–
Resets the ErrorBits and warning outputs
–
Clears Integral action
–
Maintains PID parameters
•
As long as Reset = TRUE, PID_3Step remains in "Inactive" mode
(State = 0).
•
TRUE to FALSE edge:
–
PID_3Step switches to the operating mode that is saved in the
Mode parameter.
ModeActivate
IN
Bool
The PID_3Step switches to the mode that is saved in the Mode parameter. FALSE to TRUE edge:
Mode
IN
Int
The desired PID mode; Activated on the leading edge of the Mode
Activate input.
ScaledInput
OUT
Real
Scaled process value
ScaledFeedback
OUT
Real
Scaled valve position feedback
Note: For an actuator without position feedback, the position of the
actuator indicated by ScaledFeedback is very imprecise. ScaledFeedback can only be used for rough estimation of the current position in
this case.
Output_UP
OUT
Bool
Digital output value for opening the valve. (Default value: FALSE)
If Config.OutputPerOn = FALSE, the parameter Output_UP is used.
Output_DN
OUT
Bool
Digital output value for closing the valve. (Default value: FALSE)
If Config.OutputPerOn = FALSE, the parameter Output_DN is used.
S7-1200 Programmable controller
602
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Parameter and type
Data type
Description
Output_PER
OUT
Word
Analog output value.
SetpointLimitH
OUT
Bool
If Config.OutputPerOn = TRUE, the parameter Output_PER is used.
Setpoint high limit. (Default value: FALSE)
If SetpointLimitH = TRUE, the absolute upper limit of the setpoint is
reached (Setpoint ≥ Config.SetpointUpperLimit).
Note: The setpoint is limited to (Setpoint ≥ Config.SetpointUpperLimit).
SetpointLimitL
OUT
Bool
Setpoint low limit. (Default value: FALSE)
If SetpointLimitL = TRUE, the absolute lower limit of the setpoint is
reached (Setpoint ≥ Config.SetpointLowerLimit).
Note: The setpoint is limited to (Setpoint ≥ Config.SetpointLowerLimit).
InputWarningH
OUT
Bool
If InputWarningH = TRUE, the input value has reached or exceeded the
warning high limit. (Default value: FALSE)
InputWarningL
OUT
Bool
If InputWarningL = TRUE, the input value has reached or exceeded the
warning low limit. (Default value: FALSE)
State
OUT
Int
Current operating mode of the PID controller. (Default value: 0)
You can change the operating mode using the Mode input parameter
and a rising edge at ModeActivate:
Error
OUT
Bool
•
State = 0: Inactive
•
State = 1: Pre-tuning
•
State = 2: Manual fine tuning
•
State = 3: Automatic mode
•
State = 4: Manual mode
•
State = 5: Substitute output value approach
•
State = 6: Transition time measurement
•
State = 7: Error monitoring
•
State = 8: Substitute output value approach with error monitoring\
•
State = 10: Manual mode without end stop signals
If Error = TRUE, at least one error message is pending. (Default value:
FALSE)
Note: The Error parameter in V1.x PID was the ErrorBits field that contained the error codes. It is now a Boolean flag indicating that an error
has occurred.
ErrorBits
OUT
DWord
The PID_3Step instruction ErrorBits parameters table (Page 607) defines the error messages that are pending. (Default value:
DW#16#0000 (no error)). ErrorBits is retentive and is reset upon a
rising edge at Reset or ErrorAck.
Note: In V1.x, the ErrorBits parameter was defined as the Error parameter and did not exist.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
603
Technology instructions
10.2 PID control
Operation of the PID_3Step controller
Figure 10-3
Operation of the PID_3Step controller as a PID T1 controller with anti-windup
S7-1200 Programmable controller
604
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Figure 10-4
Operation of the PID_3Step controller without position feedback
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
605
Technology instructions
10.2 PID control
Figure 10-5
Operation of the PID_3Step controller with position feedback enabled
S7-1200 Programmable controller
606
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
10.2.3.2
PID_3Step instruction ErrorBit parameters
If several errors are pending, the values of the error codes are displayed by means of binary
addition. The display of error code 0003, for example, indicates that the errors 0001 and
0002 are also pending.
Table 10- 24 PID_3STEP instruction ErrorBit parameters
ErrorBit (DW#16#...)
Description
0000
No error
0001 1, 2
The Input parameter is outside the process value limits.
Input > Config.InputUpperLimit
Input < Config.InputLowerLimit
0002
2, 3
Invalid value at the Input_PER parameter. Check whether an error is pending at the analog input.
0004 4
Error during fine tuning. Oscillation of the process value could not be maintained.
0010 4
The setpoint was changed during tuning.
Note: You can set the permitted fluctuation on the setpoint at the CancelTuningLevel tag.
0020
Pre-tuning is not permitted during fine tuning.
Note: If ActivateRecoverMode = TRUE before the error occurred, PID_3Step
remains in fine tuning mode.
0080 4
Error during pre-tuning. Incorrect configuration of output value limits.
Check whether the limits of the output value are configured correctly and
match the control logic.
0100 4
Error during fine tuning resulted in invalid parameters.
0200
2, 3
Invalid value at the Input parameter: Value has an invalid number format.
0400
2, 3
Calculating the output value failed. Check the PID parameters.
0800 1, 2
Sampling time error: PID_3Step is not called within the sampling time of the
cyclic interrupt OB.
1000 2, 3
Invalid value at the Setpoint parameter: Value has an invalid number format.
2000 1, 2, 5
Invalid value at the Feedback_PER parameter.
Check whether an error is pending at the analog input.
4000 1, 2, 5
Invalid value at the Feedback parameter: Value has an invalid number format.
8000 1, 2
Error during digital position feedback. Actuator_H = TRUE and Actuator_L =
TRUE.
The actuator cannot be moved to the substitute output value and remains in
its current position. Manual mode is not possible in this state.
In order to move the actuator from this state, you must deactivate the "Actuator end stop" (Config.ActuatorEndStopOn = FALSE) or switch to manual
mode without end stop signals (Mode = 10).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
607
Technology instructions
10.2 PID control
ErrorBit (DW#16#...)
Description
10000
Invalid value at the ManualValue parameter: Value has an invalid number
format.
The actuator cannot be moved to the manual value and remains in its current position.
Assign a valid value in ManualValue or move the actuator in manual mode
with Manual_UP and Manual_DN.
20000
Invalid value at the SavePosition tag: Value has an invalid number format.
The actuator cannot be moved to the substitute output value and remains in
its current position.
40000
Invalid value at the Disturbance parameter: Value has an invalid number
format.
Note: If automatic mode was active and ActivateRecoverMode = FALSE
before the error occurred, Disturbance is set to zero. PID_3Step remains in
automatic mode.
Note: If pre-tuning or fine tuning mode was active and ActivateRecoverMode
= TRUE before the error occurred, PID_3Step switches to the operating
mode that is saved in the Mode parameter. If Disturbance in the current
phase has no effect on the output value, tuning is not canceled.
The error has no effect during transition time measurement.
1
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_3Step remains in automatic mode.
2
Note: If pre-tuning, fine tuning, or transition time measurement mode were active and ActivateRecoverMode = TRUE before the error occurred, PID_3Step switches to the operating mode
that is saved in the Mode parameter.
3
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_3Step switches to "Approach substitute output value with error monitoring" or "Error monitoring" mode. As soon as the error is no longer pending, PID_3Step switches back to automatic
mode.
4
Note: If ActivateRecoverMode = TRUE before the error occurred, PID_3Step cancels the tuning
and switches to the operating mode that is saved in the Mode parameter.
5
The actuator cannot be moved to the substitute output value and remains in its current position. In
manual mode, you can change the position of the actuator only with Manual_UP and Manual_DN,
and not with ManualValue.
S7-1200 Programmable controller
608
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
10.2.3.3
PID_3Step instruction Warning parameters
If the PID controller has several warnings pending, it displays the values of the error codes
by means of binary addition. The display of error code 0003, for example, indicates that the
errors 0001 and 0002 are pending.
Table 10- 25 PID_Compact instruction Warning parameters
Warning (DW#16#...)
Description
0000
No warning pending.
0001 1
The point of inflection was not found during pretuning.
0002
Oscillation was enforced during “tuning in run”. (The "Warning" parameter suppresses this
warning and is only visible in the “WarningInternal” parameter for diagnostic purposes.)
0004 1
The setpoint was limited to the configured limits.
0008
Not all the necessary controlled system properties were defined for the selected method of
calculation. Instead, the PID parameters were calculated using the TIR.TuneRuleHeat /
TIR.TuneRuleCool = 3 method.
0010
The operating mode could not be changed because Reset = TRUE or ManualEnable =
TRUE.
0020
The cycle time of the calling OB limits the sampling time of the PID algorithm. Improve results by using shorter OB cycle times.
0040 1
The process value exceeded one of its warning limits.
0080
Invalid value at Mode. The operating mode is not switched.
0100
1
1
1
The manual value was limited to the limits of the controller output.
0200
The specified rule for tuning is not supported. No PID parameters are calculated.
1000
The substitute output value cannot be reached because it is outside the output value limits.
Note: The PID controller deleted the following warnings automatically as soon as the cause is eliminated or the user
action repeated with valid parameters: 0001, 0004, 0008, 0040, and 0100.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
609
Technology instructions
10.2 PID control
10.2.4
PID_Temp
10.2.4.1
PID_Temp instruction
The PID_Temp instruction provides a universal PID controller that allows handling of the
specific requirements of temperature control.
Table 10- 26 PID_Temp instruction
LAD / FBD
SCL
"PID_Temp_1"(
Setpoint:=_real_in_,
Input:=_real_in_,
Input_PER:=_int_in_,
Disturbance:=_real_in_,
ManualEnable:=_bool_in_,
ManualValue:=_real_in_,
ErrorAck:=_bool_in_,
Reset:=_bool_in_,
ModeActivate:=_bool_in_,
Mode:=_int_in_,
Master:=_dword_in
Save:=_dword_in
ScaledInput=>_real_out_,
OutputHeat=>_real_out_,
OutputCool=>_real_out_,
OutputHeat_PER=>_int_out_,
OutputCool_PER=>_int_out_,
OutputHeat_PWM=>_bool_out_,
OutputCool_PWM=>_bool_out_,
SetpointLimit_H=>_bool_out_,
SetpointLimit_L=>_bool_out_,
InputWarning_H=>_bool_out_,
InputWarning_L=>_bool_out_,
State=>_int_out_,
Error=>_bool_out_,
ErrorBits=>_dword_out_);
Description
PID_Temp provides these capabilities:
•
Heating and cooling of the process with
different actuators
•
Integrated autotuning to handle temperature processes
•
Cascading to process more than one
temperature that depends on the same
actuator
1
STEP 7 automatically creates the technology object and instance DB when you insert the instruction. The instance DB
contains the parameters of the technology object.
2
In the SCL example, "PID_Temp_1" is the name of the instance DB.
S7-1200 Programmable controller
610
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Table 10- 27 Data types for the parameters
Parameter and type
Data type
Description
Setpoint
IN
Real
Setpoint of the PID controller in automatic mode. (Default value: 0.0)
Input
IN
Real
A tag of the user program is used as the source of the process value.
(Default value: 0.0)
If you are using the Input parameter, you must set Config.InputPerOn = FALSE.
Input_PER
IN
Int
An Analog input is used as the source of the process value. (Default
value: 0)
If you are using the Input_PER parameter, you must set Config.InputPerOn = TRUE.
Disturbance
IN
Real
Disturbance variable or pre-control value
ManualEnable
IN
Bool
Enables or disables the manual operation mode. (Default value:
FALSE):
•
A FALSE to TRUE edge activates Manual mode, while State = 4,
Mode remains unchanged.
As long as ManualEnable = TRUE, you cannot change the operating mode using a rising edge at ModeActivate or use the commissioning dialog.
A TRUE to FALSE edge activates the operating mode that is assigned by Mode.
Note: We recommend that you change the operating mode using
ModeActivate only.
•
ManualValue
IN
Real
Output value for manual operation. (Default value: 0.0)
You can use values from Config.OutputLowerLimit to Config.OutputUpperLimit.
ErrorAck
IN
Bool
Resets the ErrorBits and warning outputs with a FALSE to TRUE edge.
(Default value: FALSE)
Reset
IN
Bool
Restarts the controller. (Default value: FALSE):
•
FALSE to TRUE edge:
–
Switches to "inactive" mode
–
Resets the ErrorBits and warning outputs
–
Clears Integral action
–
Maintains PID parameters
•
As long as Reset = TRUE, PID_Temp remains in Inactive mode
(State = 0).
•
TRUE to FALSE edge:
–
ModeActivate
IN
Bool
PID_Temp switches to the operating mode that is saved in the
Mode parameter.
The PID_Temp switches to the operating mode that is saved in the
Mode parameter with a FALSE to TRUE edge. (Default value: FALSE)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
611
Technology instructions
10.2 PID control
Parameter and type
Mode
IN/OUT
Data type
Description
Int
Activated on the leading edge of the Mode Activate input.
Operating mode selection (Default value: 0.0):
•
Mode = 0: Inactive
•
Mode = 1: Pretuning
•
Mode = 2: Fine tuning
•
Mode = 3: Automatic mode
• Mode = 4: Manual mode
“Substitute output value with error monitoring” (State = 5). This cannot
be activated by the user; it is only an automatic error reaction.
Master
IN/OUT
DWord
Slave
IN/OUT
DWord
Cascade connection to master (AntiWindUp and tuning conditions).
(Default value: DW#16#0000)
•
Bits 0 - 15: Not used in PID_Temp instruction
•
Bits 16 - 23: Limit counter: A slave increments this value if it reaches its limitation. The number of slaves in limitation is processed for
Anti-Windup-functionality (Refer to the Config.Cascade.AntiWindUpMode parameter.
•
Bit 24: IsAutomatic: This bit is set to "1" if all slaves of this controller
are in Automatic mode and are processed to check conditions for
tuning in a cascade. This bit is identical to the AllSlaveAutomaticState parameter.
•
Bit 25: "IsReplacement-Setpoint": This bit is set to "1" if a slave of
this controller has the "Replacement Setpoint" activated and is processed to check conditions for tuning in a cascade. The inverted
value is stored in the NoSlaveReplacementSetpoint parameter.
ScaledInput
OUT
Real
Scaled process value. (Default value: 0.0)
OutputHeat1
OUT
Real
Output value for heating in REAL format. (Default value: 0.0)
This output value is calculated, independent from the output selection,
using the Config.Output.Heat.Select parameter.
OutputCool1
OUT
Real
Output value for cooling in REAL format. (Default value: 0.0)
This output value is calculated, independent from the output selection,
using the Config.Output.Cool.Select parameter.
OutputHeat_PER1
OUT
Int
Output value for heating in peripheral format (Default value: 0)
This output value is only calculated if selected using the Config.Output.Heat.Select = 2 parameter. If not selected, this output is
always "0".
OutputCool_PER1
OUT
Int
Output value for cooling in peripheral format (Default value: 0)
This output value is only calculated if selected using the Config.Output.Cool.Select = 2 parameter. If not selected, this output is
always "0".
OutputHeat_PWM1
OUT
Bool
Pulse-width-modulated output value for heating. (Default value: FALSE)
This output value is only calculated if selected using the Config.Output.Heat.Select = 1 (default value) parameter. If not selected,
this output is always FALSE.
S7-1200 Programmable controller
612
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Parameter and type
OutputCool_PWM1
OUT
Data type
Description
Bool
Pulse-width-modulated output value for cooling. (Default value: FALSE)
This output value is only calculated if selected using the Config.Output.Cool.Select = 1 (default value) parameter. If not selected, this
output is always FALSE.
SetpointLimit_H
OUT
Bool
Setpoint high limit. (Default value: FALSE)
If SetpointLimit_H = TRUE, the absolute setpoint upper limit is reached
(Setpoint ≥ Config.SetpointUpperLimit).
The setpoint is limited to Config.SetpointUpperLimit.
SetpointLimit_L
OUT
Bool
Setpoint low limit. (Default value: FALSE)
If SetpointLimit_L = TRUE, the absolute setpoint lower limit is reached
(Setpoint ≤ Config.SetpointLowerLimit).
The setpoint is limited to Config.SetpointLowerLimit.
InputWarning_H
OUT
Bool
If InputWarning_H = TRUE, the process value has reached or exceeded the warning high limit. (Default value: FALSE)
InputWarning_L
OUT
Bool
If InputWarning_L = TRUE, the process value has reached or fallen
below the warning low limit. (Default value: FALSE)
State
OUT
Int
Current operating mode of the PID controller. (Default value: 0)
You can change the operating mode using the Mode input parameter
and a rising edge at ModeActivate:
Error
OUT
Bool
•
State = 0: Inactive
•
State = 1: Pre-tuning
•
State = 2: Fine tuning
•
State = 3: Automatic mode
•
State = 4: Manual mode
•
State = 5: Substitute output value with error monitoring
If Error = TRUE, at least one error message is pending in this cycle.
(Default value: FALSE)
Note: The Error parameter in V1.x PID was the ErrorBits field that contained the error codes. It is now a Boolean flag indicating that an error
has occurred.
ErrorBits
OUT
DWord
The PID_Temp instruction, ErrorBits parameters table
(Page 619)defines the error messages that are pending. (Default value:
DW#16#0000 (no error)). ErrorBits is retentive and is reset upon a
rising edge at Reset or ErrorAck.
Note: In V1.x, the ErrorBits parameter was defined as the Error parameter and did not exist.
1
Warning
OUT
DWord
The PID_Temp instruction, Warning parameters table (Page 621) defines the user-relevant warning messages that are pending. (Default
value: DW#16#0000 (no warning)).
WarningInternal
OUT
DWord
The PID_Temp instruction, WarningInternal parameters table defines
the warning internal messages that are pending (includes all warnings).
(Default value: DW#16#0000 (no warning internal)).
You can use the outputs of the Output, Output_PER, and Output_PWM parameters in parallel.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
613
Technology instructions
10.2 PID control
Operation of the PID_Temp controller
Selecting heating and/or cooling control
You must first select if you need a cooling device in addition to the heating output at
parameter "ActivateCooling". Afterwards, you must define if you want to use two PIDparameter-sets (advanced mode) or only one PID-parameter-set with an additional
heating/cooling-factor at parameter "AdvancedCooling".
Using CoolFactor
In case you want to apply a heating/cooling-factor, you must define the value manually. You
have to identify the value from the technical data of your application (ratio of proportional
gain of the actuators (for example, the ratio of maximum heating- and cooling-power of the
actuators) and assign it to parameter "CoolFactor". A heating/cooling-factor of 2.0 means
that the heating device is two times more effective than the cooling device. If you use cooling
factor, PID_Temp calculates the output signal and, depending on its sign, multiply the output
signal with the heating/cooling-factor (when sign is negative) or not (when sign is positive).
Using two PID-parameter-sets
Different PID-parameter-sets for heating and cooling can be automatically detected during
commissioning. You can expect a better control performance compared to heating/coolingfactor because, in addition to different proportional gains, you can consider different delay
times with two parameters-sets. However, the disadvantage is that this can take more time
for the tuning process. If PID-parameter switchover is activated (Config.AdvancedCooling =
TRUE), the PID_Temp controller detects in "Automatic mode" (controlling is active) if heating
or cooling is necessary at that time and uses PID-parameter-sets for control.
ControlZone
With the PID_Temp controller, you can define a control zone for each parameter-set at
parameter "ControlZone". If the control deviation (setpoint – input) is within the control zone,
PID_Temp uses the PID-algorithm to calculate the output signals. However, if the control
deviation leaves the defined range, the output is set to the maximum heating or maximum
cooling output value (cooling output activated) / minimum heating output value (cooling
output deactivated). You can use this functionality to reach the desired setpoint faster,
especially for initial heating-up of slow temperature processes.
DeadZone
In the "DeadZone" parameter, you can define a width of control deviation for heating and
cooling that is neglected by the PID-algorithm. This means a control deviation within this
range is suppressed, and the PID_Temp controller behaves like the setpoint and process
values are identical. Thus, you can reduce unnecessary intervention by the controller around
the setpoint and conserve the actuator. If you want to apply a DeadZone, you must define
the value manually. Auto tuning does not automatically set the DeadZone value. DeadZone
is symmetric (between -Retain.CtrlParams.Heat.DeadZone and
+Retain.CtrlParams.Heat.DeadZone) for heating controllers without cooling or
heating/cooling controllers using CoolFactor. DeadZone can be asymmetric (between Retain.CtrlParams.Cool.DeadZone and +Retain.CtrlParams.Heat.DeadZone) for
heating/cooling controllers using two PID-parameter sets.
S7-1200 Programmable controller
614
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
PID_Temp controller operations
The following block diagrams illustrate the PID_Temp instruction standard and cascade
operations:
Figure 10-6
PID_Temp_Operation_Block_Diagram
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
615
Technology instructions
10.2 PID control
Figure 10-7
PID_Temp_Cascade_Operation_Block_Diagram
Cascading controllers
You can cascade temperature PID controllers to process more than one temperature that
depend on the same actuator.
Call order
You must call cascaded PID controllers in the same OB cycle. First, you must call the
master, then, the next slave(s) in the control signal flow, and finally on to the last slave in the
cascade. The PID_Temp instruction does not make an automatic check of call order.
S7-1200 Programmable controller
616
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Communication connections
When cascading controllers, you must connect the master and slave so that they can share
information with each other. You must connect a slave’s “Master” IN/OUT parameter to its
master’s “Slave” IN/OUT parameter in the signal flow direction.
This shows a connection of PID_Temp controllers in a cascade with two sub-cascades:
"PID_Temp1" provides the setpoint. The configuration connects the outputs of "PID_Temp2",
"PID_Temp3", "PID_Temp5", "PID_Temp6", and "PID_Temp8" to the process:
Figure 10-8
PID_Temp_Cascading_communication_connection
Replacement setpoint
The PID_Temp instruction provides a second setpoint input at the “ReplacementSetpoint”
parameter that you can activate by setting the parameter “ReplacementSetpointOn” = TRUE.
You can use “ReplacementSetpoint” as your setpoint input during commissioning or tuning of
a slave controller without having to disconnect the output-to-setpoint connection between
master and slave. This connection is necessary for normal operation of the cascade.
In this way, you do not have to change your program and download it if you want to
temporarily separate a slave from its master. You only have to activate the
"ReplacementSetpoint" and deactivate it again when you finish.The setpoint value is
effective for the PID algorithm when you can see the value at the “CurrentSetpoint”
parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
617
Technology instructions
10.2 PID control
Autotuning
An autotuning for a cascaded master controller must meet these requirements:
● Be commissioned from its inner slave to the first master.
● All slaves of the master have to be in “Automatic mode".
● The output of the master must be the setpoint for the slaves.
PID_Temp instruction will provide the following support for autotuning in the cascade:
● If you start autotuning for a master controller, the master checks to see if all slaves are in
“Automatic mode” and for the deactivation of the Replacement-Setpoint-functionality for
all slaves (“ReplacementSetpointOn” = FALSE). If you do not meet these conditions, you
cannot autotune the master. The master cancels the tuning, goes to “Inactive” mode" (if
“ActivateRecoverMode” = FALSE), or back to the mode stored in the “Mode” parameter (if
“ActivateRecoverMode” = TRUE). The master displays the error message 200000hex
("Error with master in the cascade. Slaves are not in automatic mode or have a substitute
setpoint enabled and are preventing tuning of the master.").
● When all slaves are in “Automatic mode”, the system sets the parameter
“AllSlaveAutomaticState” = TRUE. You can apply this parameter in your programs or
localize the cause of error 200000hex.
● When the "ReplacementSetpoint" is deactivated for all slaves, the system sets the
parameter “NoSlaveReplacementSetpoint” = TRUE. You can apply this parameter in their
programs or localize the cause of error 200000hex.
When the PID_Temp instruction commissioning dialog is used, you have further support for
cascade tuning (Page 642).
Operation modes and error handling
The PID_Temp controller does not allow switching of the operating mode by its master or
slaves. This means that a master inside the cascade stays in its current mode when a slave
raises an error. This is an advantage if two or more parallel slaves operate with this master
controller; an error in one chain does not shut down the parallel chain.
Similarly, a slave inside the cascade stays in its current operation mode, if its master has an
error. However, further operation of the slave then depends on the configuration of the
master because the slave’s setpoint is the master’s output. This means that if you configure
the master with “ActivateRecoverMode” = TRUE and an error occurs, the master outputs the
last valid or a substitute output value as setpoint for the slave. If you configure the master
with “ActivateRecoverMode” = FALSE, the master switchs to “Inactive mode" and sets all
outputs to "0.0" so that the slave uses "0.0" as its setpoint.
Because only the slave controllers have direct access to the actuators and these stay in their
operating mode in case of a master error, you can avoid damage to the process. For
example, for plastics processing devices, it is fatal for the slaves to stop working, shut down
the actuators, and allow the plastic to harden inside the device solely because the master
controller had an error.
S7-1200 Programmable controller
618
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Anti-windup
A slave in a cascade gets its setpoint from the output of his master. If the slave reaches its
own output limits while the master still sees a control deviation (setpoint – input), the master
freezes or reduces its integration contribution to prevent a so-called "WindUp". In case of a
"WindUp", the master increases its integration contribution to a very large value and must
reduce it first, before the controller can again have a normal reaction. Such a "WindUp"
affects the dynamic of the control negatively. The PID_Temp provides ways to prevent this
effect in a cascade by configuring the parameter “Config.Cascade.AntiWindUpMode” of the
master controller:
Value
10.2.4.2
Description
0
Deactivates Anti-Windup functionality.
1
Reduces the integration contribution of the master controller at the ratio “slaves
in limitation” to “existing slaves” (parameter “CountSlaves”).
2
Freezes the integration contribution of the master as soon as one slave reaches
its limitation. Only relevant if "Config.Cascade.IsMaster" = TRUE.
PID_Temp ErrorBit parameters
If the PID controller has several warnings pending, it displays the values of the error codes
by means of binary addition. The display of error code 0003, for example, indicates that the
errors 0001 and 0002 are pending.
Table 10- 28 PID_Temp instruction ErrorBit parameters
ErrorBit (DW#16#...)
Description
0000
No error
0001 1, 2
The Input parameter is outside the process value limits.
Input > Config.InputUpperLimit
Input < Config.InputLowerLimit
0002
2, 3
Invalid value at the Input_PER parameter. Check whether an error is pending at the analog input.
0004 4
Error during fine tuning. Oscillation of the process value could not be maintained.
0008 4
Error at start of pre-tuning. The process value is too close to the setpoint.
Start fine tuning.
0010 4
The setpoint was changed during tuning.
Note: You can set the permitted fluctuation on the setpoint at the CancelTuningLevel tag.
0020
Pre-tuning is not permitted during fine tuning.
Note: If ActivateRecoverMode = TRUE before the error occurred,
PID_Temp remains in fine tuning mode.
0040 4
Error during pretuning. The cooling could not reduce the process value.
0080 4
Error during pre-tuning. Incorrect configuration of output value limits.
Check whether the limits of the output value are configured correctly and
match the control logic.
0100 4
Error during fine tuning resulted in invalid parameters.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
619
Technology instructions
10.2 PID control
ErrorBit (DW#16#...)
Description
0200 2, 3
Invalid value at the Input parameter: Value has an invalid number format.
0400
Calculation of the output value failed. Check the PID parameters.
2, 3
0800 1, 2
Sampling time error: PID_Temp is not called within the sampling time of the
cyclic interrupt OB.
1000 2, 3
Invalid value at the Setpoint parameter: Value has an invalid number format.
10000
Invalid value at the ManualValue parameter: Value has an invalid number
format.
Note: If ActivateRecoverMode = TRUE before the error occurred,
PID_Temp uses SubstituteOutput as the output value. As soon as you assign a valid value in the ManualValue parameter, PID_Temp uses it as the
output value.
20000
Invalid value at the SubstituteValue tag: Value has an invalid number format.
PID_Temp uses the output value low limit as the output value.
Note: If automatic mode was active before the error occurred, ActivateRecoverMode = TRUE, and the error is no longer pending, PID_Temp
switches back to automatic mode.
40000
Invalid value at the Disturbance parameter: Value has an invalid number
format.
Note: If automatic mode was active and ActivateRecoverMode = FALSE
before the error occurred, Disturbance is set to zero. PID_Temp remains in
automatic mode.
Note: If pre-tuning or fine tuning mode was active and ActivateRecoverMode = TRUE before the error occurred, PID_Temp switches to the operating mode that is saved in the Mode parameter. If Disturbance in the current
phase has no effect on the output value, tuning is not canceled.
200000
Error with master in the cascade. Slaves are not in automatic mode or have
a substitute setpoint enabled, preventing tuning of the master.
400000
The PID controller does not permit pretuning for heating while cooling is
active.
800000
The process value must be close to the setpoint in order to start pretuning
for cooling.
1000000
Error starting tuning. “Heat.EnableTuning” and “Cool.EnableTuning” are not
set or do not match the configuration.
2000000
Pretuning for cooling requires successful pretuning for heating.
S7-1200 Programmable controller
620
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
10.2.4.3
ErrorBit (DW#16#...)
Description
4000000
Error starting fine tuning. “Heat.EnableTuning” and “Cool.EnableTuning”
cannot be set at the same time.
8000000
Error during PID parameter calculation resulted in invalid parameters (for
example, negative Gain; the current PID parameters remain unchanged and
tuning has no effect).
1
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_Temp remains in automatic mode.
2
Note: If pre-tuning or fine tuning mode was active before the error occurred and ActivateRecoverMode = TRUE, PID_Temp switches to the operating mode that is saved in the Mode parameter.
3
Note: If automatic mode was active before the error occurred and ActivateRecoverMode = TRUE,
PID_Compact outputs the configured substitute output value. As soon as the error is no longer
pending, PID_Temp switches back to automatic mode.
4
Note: If ActivateRecoverMode = TRUE before the error occurred, PID_Temp cancels the tuning
and switches to the operating mode that is saved in the Mode parameter.
PID_Temp Warning parameters
If the PID controller has several warnings pending, it displays the values of the error codes
by means of binary addition. The display of error code 0003, for example, indicates that the
errors 0001 and 0002 are pending.
Table 10- 29 PID_Temp instruction Warning parameters
Warning (DW#16#...)
Description
0000
No warning pending.
0001
1
0002
The point of inflection was not found during pretuning.
Oscillation was enforced during “tuning in run”. (The "Warning" parameter
suppresses this warning and is only visible in the “WarningInternal” parameter for diagnostic purposes.)
0004 1
The setpoint was limited to the configured limits.
0008
Not all the necessary controlled system properties were defined for the
selected method of calculation. Instead, the PID parameters were calculated
using the TIR.TuneRuleHeat / TIR.TuneRuleCool = 3 method.
1
0010
The operating mode could not be changed because Reset = TRUE or ManualEnable = TRUE.
0020
The cycle time of the calling OB limits the sampling time of the PID algorithm. Improve results by using shorter OB cycle times.
0040 1
The process value exceeded one of its warning limits.
0080
Invalid value at Mode. The operating mode is not switched.
0100
1
The manual value was limited to the limits of the controller output.
0200
The specified rule for tuning is not supported. No PID parameters are calculated.
1000
The substitute output value cannot be reached because it is outside the
output value limits.
4000
The specified output selection for heating and/or cooling is not supported.
Only OutputHeat and OutputCool are active.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
621
Technology instructions
10.2 PID control
1
10.2.5
Warning (DW#16#...)
Description
8000
The specified value for the PIDSelfTune.SUT.AdaptDelayTime parameter is
not supported, so the default value "0" is used.
10000
The specified value for the PIDSelfTune.SUT.CoolingMode parameter is not
supported, so the default value "0" is used.
Note: The PID controller deleted the following warnings automatically as soon as the cause is
eliminated or the user action repeated with valid parameters: 0001, 0004, 0008, 0040, and 0100.
Configuring the PID_Compact and PID_3Step controllers
The parameters of the technology object determine the operation of the PID controller. Use the icon to open the configuration editor.
Table 10- 30 Example configuration settings for the PID_Compact instruction
Settings
Basic
Process
value
Description
Controller type
Selects the engineering units.
Invert the control logic
Allows selection of a reverse-acting PID loop.
•
If not selected, the PID loop is in direct-acting mode and the output of PID loop
increases if input value < setpoint.
•
If selected, the output of the PID loop increases if the input value > setpoint.
Enable last mode after
CPU restart
Restarts the PID loop after it is reset or if an input limit has been exceeded and
returned to the valid range.
Input
Selects either the Input parameter or the Input_PER parameter (for analog) for the
process value. Input_PER can come directly from an analog input module.
Output
Selects either the Output parameter or the Output_PER parameter (for analog) for
the output value. Output_PER can go directly to an analog output module.
Scales both the range and the limits for the process value. If the process value goes below the low limit or
above the high limit, the PID loop goes to inactive mode and sets the output value to 0.
To use Input_PER, you must scale the analog process value (input value).
S7-1200 Programmable controller
622
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Table 10- 31 Example configuration settings for the PID_3Step instruction
Settings
Basic
Description
Controller type
Selects the engineering units.
Invert the control logic
Allows selection of a reverse-acting PID loop.
Activate mode after
CPU restart
•
If not selected, the PID loop is in direct-acting mode, and the output of PID loop
increases if the input value < setpoint).
•
If selected, the output of the PID loop increases if the input value > setpoint.
Restarts the PID loop after it is reset or if an input limit has been exceeded and
returned to the valid range.
Set Mode to: Defines the mode that the user wants the PID to go to after restart.
Process
value
Input
Selects either the Input parameter or the Input_PER parameter (for analog) for the
process value. Input_PER can come directly from an analog input module.
Output
Selects either to use the digital outputs (Output_UP and Output_DN) or to use the
analog output (Output_PER) for the output value.
Feedback
Selects the type of device status returned to the PID loop:
•
No feedback (default)
•
Feedback
•
Feedback_PER
Scales both the range and the limits for the process value. If the process value goes below the low limit or
above the high limit, the PID loop goes to inactive mode and sets the output value to 0.
To use Input_PER, you must scale the analog process value (input value).
Actuator
Motor transition
time
Sets the time from open to close for the valve. (Locate this value on the data sheet or
the faceplate of the valve.)
Minimum ON time
Sets the minimum movement time for the valve. (Locate this value on the data sheet or
the faceplate of the valve.)
Minimum OFF
time
Sets the minimum pause time for the valve. (Locate this value on the data sheet or the
faceplate of the valve.)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
623
Technology instructions
10.2 PID control
Settings
Advanced
Description
Reaction to error
Defines the behavior of the valve when an error is detected or when the PID loop is
reset. If you select to use a substitute position, enter the "Safety position". For analog
feedback or analog output, select a value between the upper or lower limit for the output. For digital outputs, you can choose only 0% (off) or 100% (on).
Scale Position
Feedback1
•
"High end stop" and "Lower end stop" define the maximum positive position (fullopen) and the maximum negative position (full-closed). "High end stop" must be
greater than "Lower end stop".
•
"High limit process value" and "Low limit process value" define the upper and lower
positions of the valve during tuning and automatic mode.
•
"FeedbackPER" ("Low" and "High") defines the analog feedback of the valve position. "FeedbackPER High" must be greater than "FeedbackPER Low".
Monitoring process Sets the warning high and low limits for the process value.
value
PID parameters
1
If the user wishes, he can enter his own PID tuning parameters in this window. The
“Enable Manual Entry” check box must be checked to allow this.
"Scale Position Feedback" is editable only if you enabled "Feedback" in the "Basic" settings.
S7-1200 Programmable controller
624
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
10.2.6
Configuring the PID_Temp controller
The parameters of the technology object determine the operation of the PID controller. Use the icon to open the configuration editor.
Table 10- 32 Example configuration settings for the PID_Temp instruction
Settings
Basic
Description
Controller type
Selects the engineering units.
Activate mode
after CPU restart
Restarts the PID loop after it is reset or if an input limit has been
exceeded and returned to the valid range.
Set Mode to: Defines the mode that the user wants the PID to go to
after restart.
Process
value
Input
Selects either the Input parameter or the Input_PER parameter (for
analog) for the process value. Input_PER can come directly from an
analog input module.
Output Heat
Selects either to use the digital outputs (OutputHeat and OutputHeat_PWM) or to use the analog output (OutputHeat_PER (analog)) for the output value.
Output Cool
Selects either to use the digital outputs (OutputCool and OutputCool_PWM) or to use the analog output (OutputCool_PER (analog)) for the output value.
Scales both the range and the limits for the process value. If the process value goes below the low limit or above the high limit, the PID loop goes to inactive mode and sets the
output value to 0.
To use Input_PER, you must scale the analog process value (input value).
Cascade
Controller is master
Sets the controller as a master and selects the number of slaves.
Controller is slave Sets the controller as a slave and selects the number of masters.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
625
Technology instructions
10.2 PID control
Controller type
Setting
Physical
quantity
Unit of
measurement
TO-DB parameter
"PhysicalQuantity"
"PhysicalUnit
Data
type
Value range
Description
Int
(Enu
m)
•
General
Pre-selection for physical
unit value
•
Temperature
(=default)
Int
(Enu
m)
•
General: Units =
%
•
Temperature:
Units (possible
selections) =
No multi-value control
and not editable in online
mode of functional view.
–
°C (=default)
–
°F
–
K
User unit selection is set
back to “0” if you change
the physical quantity.
Activate
mode
after
CPU
restart
"RunModeByStartup"
Bool
Checkbox
If set to TRUE (=default),
the controller switches to
the state that is stored in
the “Mode” variable after
a powercycle (Power on off - on) or PLC STOP-toRUN transition. Otherwise, the PID_Temp
remains in “Inactive”
mode.
Set
mode to
"Mode"
Int
(Enu
m)
Modes (possible
selections):
The engineering station
(ES) sets the start value
of the“Mode” variable
according to user selection.The default value of
Mode (stored inTO-DB) is
Manual Mode.
•
0: Inactive
•
1: Pretuning
•
2: Fine tuning
•
3: Automatic
mode
•
4: Manual mode
(=default)
S7-1200 Programmable controller
626
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Input / output parameters
Setting
Setpoint
TO-DB parameter
Setpoint
Data
type
Real)
Value range
Real
Description
Only accessible in Property Page.
No multi value control in
online mode of functional view.
Selection "Config.InputPerOn"
input
Input
Input or Input_PER
Bool
(Enu
m)
Real
or Int
Bool
Selects which kind of
input to use.
Possible selections:
Real or Int
•
FALSE: “Input” (Real)
•
TRUE: “Input_PER
(analog)”
Only accessible in Properties page.
No multi value control in
online mode of functional view.
Selection "Config.Output.Heat.Select"
Output
(heating)
Int
(Enu
m)
2 >= Config.Output.
Heat.Select
>= 0
Selects which kind of
output to use for heating.
Possible selections:
•
“OutputHeat” (Real)
•
“OutputHeat_PWM”
(Bool) (=default)
“OutputHeat_PER
(analog)” (Word)
Is set to “OutputHeat”
once, if “This controller
is a master” checkbox in
the “Cascade” section is
activated by user.
•
Output
OutputHeat, OutputHeat_PER,
(heating) or OutputHeat_PWM
Real
or Int
or
Bool
Real, Int, or Bool
Only accessible in Properties page.
No multi value control in
online mode of functional view.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
627
Technology instructions
10.2 PID control
Setting
Activate
output
(cooling)
TO-DB parameter
"Config.ActivateCooling"
Data
type
Bool
Value range
Bool
Description
Checking this checkbox:
•
Sets the "Config.Output.
Heat.PidLowerLimit
= 0.0 once.
•
Sets the
"Config.ActivateCooling"
parameter to TRUE,
instead of FALSE if
unchecked
(=default).
•
Activates all other
“Output (cooling)”
controls (in “Basic
settings” and other
views).
•
Changes the line
from the PID symbol
to the controls from
gray to black.
“This controller is a
master” checkbox in
the “Cascade” section is disabled.
Note: Only available if
you do not configure the
controller as a master for
a cascade (“This controller is a master”checkbox
in the “Cascade” section
is deactivated;
"Config.Cascade.IsMaster" =
FALSE).
•
S7-1200 Programmable controller
628
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Setting
TO-DB parameter
Selection "Config.Output.Cool.Select"
Output
(cooling)
Data
type
Int
(Enu
m)
Value range
2 >= Config.Output.
Heat.Select
>= 0
Description
Selects which kind of
output to use for cooling.
Possible selections:
•
“OutputCool” (Real)
•
“OutputCool_PWM”
(Bool) (=default)
“OutputCool_PER
(analog)” (Word)
Only available if you
check “Activate output
(cooling)”;
(Config.ActivateCooling
= TRUE).
•
Output
(cooling)
OutputCool, OutputCool_PER,
or OutputCool_PWM
Real
or Int
or
Bool
Real, Int, or Bool
Only accessible in Properties page.
No multi value control in
online mode of functional view.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
629
Technology instructions
10.2 PID control
Cascade parameters
The following parameters enable you to select controllers as masters or slaves and to
determine the number of slave controllers that receive their setpoint directly from the master
controller:
Setting
TO-DB parameter
This
"Config.Cascade.IsMaster"
controller
is a
master
Data
type
Bool
Value range
Bool
Description
Shows if this controller is
a master in a cascade.
When you check this
checkbox, you perform
the following:
•
Set the parameter
"Config.Cascade.IsMaster
" to TRUE, instead of
FALSE if unchecked
(=default).
•
Set “Selection Output
(heating)” in “Input /
output parameters”
section to “OutputHeat” once (Config.Output.Heat.Selec
t = 0).
•
Enable “Number of
Slaves” input field.
Disable “Activate
output (cooling)”
checkbox in “Input /
output parameters”
section.
Note: Only available if
cooling output of this
controller is deactivated
(“Activate output (cooling)” checkbox in “Input /
output parameters” section deactivated (Config.ActivateCooling =
FALSE).
•
S7-1200 Programmable controller
630
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Setting
TO-DB parameter
Data
type
Value range
Description
Number "Config.Cascade.CountSlaves"
of slaves
Int
255 >= Config.Cascade.
CountSlaves
>= 1
Number of slave controllers that get their setpoint directly from this
master controller. The
PID_Temp instruction
processes this value,
along with others, for
anti-winduphandling."Number of
slaves is only available if
“This controller is a master” checkbox is activated (Con(Config.Cascade.IsMaster =
TRUE).
This
"Config.Cascade.IsSlave"
controller
is a
slave
Bool
Bool
Shows if this controller is
a slave in a cascade.
When you check this
checkbox, you set the
parameter "Config.Cascade.IsSlave" to
TRUE, instead of FALSE
if unchecked (=default).
You must check this
checkbox in the property
page to enable the “SelectionMaster” dropdown
list.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
631
Technology instructions
10.2 PID control
Example: Cascading controllers
In the “Basic settings” dialog below, you see the “Input / output parameters” section and the
“Cascade” section for slave controller "PID_Temp_2" after selecting "PID_Temp_1" as
master. You make the connections between master and slave controller:
Network 1: In these networks, you make the connection between the "PID_Temp_1" master
and the "PID_Temp_2" slave in the programming editor:
S7-1200 Programmable controller
632
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Network 2: You make the connection between the "PID_Temp_1" master’s “OutputHeat” and
"Slave" parameters to the "PID_Temp_2" slave’s “Setpoint” and "Master" parameters,
respectively:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
633
Technology instructions
10.2 PID control
Autotuning of temperature processes
The PID_Temp instruction provides two modes for auto tuning:
● “Pretuning” (parameter “Mode” = 1)
● “Finetuning” (parameter “Mode” = 2)
Depending on the controller configuration, different variants of these tuning methods are
available:
Configuration
Controller with heating
output
Associated
TO-DB values
•
Config.ActivateCooling •
= FALSE
Config.ActivateCooling
= TRUE
•
Config.ActivateCooling
= TRUE
•
Config.AdvancedCooling
= irrelevant
•
Config.AdvancedCooling =
FALSE
•
Config.AdvancedCooling =
TRUE
•
“Pretuning heating”
•
“Pretuning heating”
•
•
“Fine tuning heating"
(cooling offset cannot
be used)
•
“Fine tuning heating"
(cooling offset can be
used)
“Pretuning heating and
cooling”
•
"Pretuning heating”
•
“Pretuning cooling”
•
“Fine tuning heating”
(cooling offset can be
used)
•
“Fine tuning cooling”
(heating offset can be
used)
Available tuning methods
Controller with heating and Controller with heating and
cooling output using cool- cooling output using two
ing factor
sets of PID parameters
S7-1200 Programmable controller
634
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Output value limits and scaling
Cooling activation disabled
If you configure the PID_Temp instruction as master for a cascade “Activate output (cooling)”
checkbox in “Basic settings” view is unchecked and disabled, all settings in the “Output
settings” view that depend on cooling activation are disabled, too.
The figure below shows the "Output value limits and scaling” section in the “Output settings”
view with cooling deactivated (OutputHeat_PWM selected in “Input / output parameters” view
and OutputHeat always enabled):
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
635
Technology instructions
10.2 PID control
Cooling activation enabled
The figure below shows the ”Output value limits and scaling” section in “Output settings”
view with cooling activated (OutputCool_PER and OutputHeat_PWM selected in “Input /
output parameters” view; OutputCool and OutputHeat always enabled):
S7-1200 Programmable controller
636
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
637
Technology instructions
10.2 PID control
Operation modes
To change the mode of operation manually, the user needs to set the “Mode” in-out
parameter of the controller and activate it by setting “ModeActivate” from FALSE to TRUE
(rising edge triggered). You must reset “ModeActivate” before the next mode change; it does
not reset automatically.
Output parameter “State” shows the current operating mode and is set to the requested
“Mode” if possible. The “State” parameter cannot be changed directly; it is only changed
through the “Mode” parameter or automatic operating mode changes by the controller.
"Mode" /
"State"
0
1
Name
Inactive
Pretuning
(startup tuning / SUT)
Description
The PID_Temp instruction:
•
Deactivates the PID-algorithm and pulse width modulation
•
Sets to "0" (FALSE) all controller outputs (OutputHeat, OutputCool, OutputHeat_PWM,OutputCool_PWM, OutputHeat_PER, OutputCool_PER), regardless of
configured output limits or offsets. You can reach this mode by setting “Mode” = 0,
“Reset” = TRUE, or by error.
This mode determines the parameters during first start up of the controller.
Unlike the PID_Compact, for the PID_Temp, you must select if you require heating tuning,
cooling tuning, or both with the “Heat.EnableTuning” and “Cool.EnableTuning” parameters.
You can activate "Pretuning" from Inactive, Automatic mode, or Manual mode.
If tuning is successful, PID_Temp switches to Automatic mode. If tuning is unsuccessful,
the switchover of the operating mode depends on “ActivateRecoverMode”.
2
Fine tuning
(tuning in run
/ TIR)
This mode determines the optimum parameterization of the PID controller at the setpoint.
Unlike the PID_Compact, for the PID_Temp, you must select if you require heating tuning
or cooling tuning with the “Heat.EnableTuning” and “Cool.EnableTuning” parameters.
You can activate "Finetuning" from Inactive, Automatic mode, or Manual mode.
If tuning is successful, PID_Temp switches to Automatic mode. If tuning is not successful,
the switchover of the operating mode depends on “ActivateRecoverMode”.
3
Automatic
mode
In Automatic mode (the standard PID control mode), the result of the PID-algorithm determines the output values.
PID_Temp switches to Inactive if an error occurs and “ActivateRecoverMode” = FALSE. If
an error occurs and “ActivateRecoverMode” = TRUE, the switchover of the operating
mode depends on the error. Refer to PID_Temp instruction ErrorBit parameters
(Page 619) for further information.
S7-1200 Programmable controller
638
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
"Mode" /
"State"
4
Name
Manual mode
Description
In this mode, the PID controller scales, limits, and transfers the value of parameter “ManualValue” to the outputs.
The PID controller assigns “ManualValue” in the scaling of the PID-algorithm
(like“PidOutputSum”), so its value decides if it is effective at the heating or cooling outputs.
You can reach this mode by setting “Mode” = 4 or “ManualEnable”= TRUE.
5
Substitute
output value
with error
monitoring
(Recover
mode)
You can activate this mode by setting "Mode" = 5. The mode is an automatic error reaction of the controller if Automatic mode is active at the moment the error occurs:
•
SetSubstituteOutput = FALSE (Last valid output value)
• SetSubstituteOutput = TRUE (Value stored in parameter "SubstituteOutput")
When PID_Temp is in “Automatic mode” and the “ActivateRecoverMode” parameter =
TRUE, PID_Temp changes to this
mode in the case of the following errors:
•
“Invalid value at "Input_PER" parameter. Check for an error at the analog input (for
example, wire broken)." (ErrorBits = DW#16#0002)
•
“Invalid value at "Input" parameter. Value is not a number.” (ErrorBits = DW#16#0200)
•
“Calculation of output value failed. Check the PID parameters.” (ErrorBits =
DW#16#0400)
“Invalid value at "Setpoint" parameter. Value is not a number.” (ErrorBits =
DW#16#1000)
If the error is no longer pending, PID_Temp will switch back to Automatic mode automatically.
•
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
639
Technology instructions
10.2 PID control
10.2.7
Commissioning the PID_Compact and PID_3Step controllers
Use the commissioning editor to configure the PID controller for autotuning at startup
and for autotuning during operation. To open the commissioning editor, click the icon
on either the instruction or the project navigator.
Table 10- 33 Sample commissioning screen (PID_3Step)
•
Measurement: To display the setpoint, the process value (input value) and the output value in a real-time trend, enter the sample time and click the
"Start" button.
•
Tuning mode: To tune the PID loop, select either
"Pre-tuning" or "Fine tuning" (manual) and click the
"Start" button. The PID controller runs through multiple phases to calculate system response and update
times. The appropriate tuning parameters are calculated from these values.
After the completion of the tuning process, you can
store the new parameters by clicking the "Upload PID
parameters" button in the "PID Parameters" section of
the commissioning editor.
If an error occurs during tuning, the output value of the
PID goes to 0. The PID mode then is set to "inactive"
mode. The status indicates the error.
S7-1200 Programmable controller
640
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
PID start value control
You can edit the actual values of the PID configuration parameters so that the behavior of
the PID controller can be optimized in online mode.
Open the "Technology objects" for your PID controller and its "Configuration" object. To
access the start value control, click the "eyeglasses icon" in the upper left corner of the
dialog:
You can now change the value of any of your PID controller configuration parameters as
shown in the figure below.
You can compare the actual value to the project (offline) start value and the PLC (online)
start value of each parameter. This is necessary to compare online/offline differences of the
Technology object data block (TO-DB) and to be informed about the values that will be used
as current values on the next Stop-to-Start transition of the PLC. In addition, a compare icon
gives a visual indication to help easily identify online/offline differences:
The figure above shows the PID parameter screen with compare icons showing which
values are different between online and offline projects. A green icon indicates that the
values are the same; a blue/orange icon indicates that the values are different.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
641
Technology instructions
10.2 PID control
Additionally, click the parameter button with the downward arrow to open a small window
that shows the project (offline) start value and the PLC (online) start value of each
parameter:
10.2.8
Commissioning the PID_Temp controller
Use the commissioning editor to configure the PID controller for autotuning at startup
and for autotuning during operation. To open the commissioning editor, click the icon
on either the instruction or the project navigator.
Table 10- 34 Sample commissioning screen (PID_Temp)
Measurement: To display the setpoint, the process value
(input value) and the output value in a real-time trend,
enter the sample time and click the "Start" button.
Tuning mode: To tune the PID_Temp loop, select either
"Pretuning" or "Finetuning" (manual) and click the "Start"
button. The PID controller runs through multiple phases
to calculate system response and update times. The
appropriate tuning parameters are calculated from these
values.
After the completion of the tuning process, you can store
the new parameters by clicking the "Upload PID parameters" button in the "PID Parameters" section of the commissioning editor.
If an error occurs during tuning, the output value of the
PID goes to "0". The PID mode then is set to "inactive"
mode. The status indicates the error.
S7-1200 Programmable controller
642
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
PWM limits
Actuators that are controlled with the software PWM function of the PID_Temp may need to
be protected from too short pulse durations (for example, a thyristor relay needs to be turned
on for more than 20 ms before it can react at all); you assign a minimum on time. The
actuator can also neglect short impulses and therefore corrupt the control quality. A
minimum off time can be necessary (for example, to prevent overheating).
To show up the PWM limits view, you must open the functional view in the Technology
objects (TO) configuration and select “PWM limits” from the “Advanced settings” node in the
navigation tree.
If you open the “PWM limits” view in the functional view and activate monitoring (“glasses”
button), all controls show the online monitor value from TO-DB with orange background color
and multi-value control, and you can edit the values (if configuration conditions are fulfilled;
refer to the table below).
Setting
Minimum
on
TO-DB parameter
Data
type
Description
"Config.Output.Heat.
MinimumOnTime"
Real
100000.0
>= "Config.Output.
Heat.
MinimumOnTime
>= 0.0
A pulse at OutputHeat_PWM" is
never shorter than this
value.
"Config.Output.Heat.
MinimumOffTime"
Real
100000.0
>= "Config.Output.
Heat.
MinimumOffTime
>= 0.0
A break at OutputHeat_PWM is never shorter than this
value.
time (heating) 1,2
Minimum
off
Value range
time (heating) 1,2
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
643
Technology instructions
10.2 PID control
Setting
Minimum
on
TO-DB parameter
Data
type
Description
"Config.Output.Cool.
MinimumOnTime"
Real
100000.0
>= Config.Output.
Cool.
MinimumOnTime
>= 0.0
A pulse at OutputCool_PWM is never shorter than this
value.
"Config.Output.Cool.
MinimumOffTime"
Real
100000.0
>= Config.Output.
Cool.
MinimumOffTime
>= 0.0
A break at OutputCool_PWM is never shorter than this
value.
time (cooling) 1,3,4
Minimum
off
Value range
time (cooling) 1,3,4
1
The field displays "s" (seconds) as the time units.
2
If the·selection Output (heating) in “Basic settings” view is not “OutputHeat_PWM” (Config.Output.Heat.Select = TRUE), you should set this value to "0.0".
3
If selection Output (cooling) in “Basic settings” view is not “OutputCool_PWM” (Config.Output.Cool.Select = TRUE), you should set this value to "0.0".
4
Only available if you check “Activate output (cooling)” in “Basic settings” view (Config.ActivateCooling = TRUE).
S7-1200 Programmable controller
644
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
PID parameters
The “Advanced settings” view, "PID Parameters” section is shown below with the cooling
and/or “PID parameterswitchover” feature deactivated.
Setting
Enable
TO-DB parameter
Data
type
Value range
Description
"Retain.CtrlParams.
SetByUser"
Bool
Bool
You must check this
checkbox to enter PID
parameters manually.
Proportional "Retain.CtrlParams.
gain (heatHeat.Gain"
ing) 2
Real
Gain >= 0.0
PID proportional gain
for heating
Integral
action time
(heating) 1,2
"Retain.CtrlParams.
Heat.Ti"
Real
100000.0 >=
Ti >= 0.0
PID integral action for
heating.
Derivative
action time
(heating) 1,2
"Retain.CtrlParams.
Heat.Td"
Real
100000.0 >=
Td >= 0.0
PID derivative action
time for heating.
Derivative
"Retain.CtrlParams.
delay coeffi- Heat.TdFiltRatio"
cient(heatin
g) 2
Real
TdFiltRatio >=
0.0
PID derivative delay
coefficient for heating
that defines the derivative lag time as coefficient from the PID
derivative time.
Proportional "Retain.CtrlParams.
action
Heat.PWeighting"
weighting(h
eating) 2
Real
1.0 >=PWeighting Weighting of the PID
>= 0.0
proportional gain for
heating in either director loopback- control
path.
Derivative
action
weighting
(heating) 2
Real
1.0 >=DWeighting Weighting of the PID
>= 0.0
derivative part for heating in either direct- or
loopback- control path.
manual
entry
"Retain.CtrlParams.
Heat.DWeighting"
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
645
Technology instructions
10.2 PID control
Setting
Sampling
time of PID
algorithm
(heating) 1,2
TO-DB parameter
"Retain.CtrlParams.
Heat.Cycle"
Data
type
Real
Value range
100000.0
>=Cycle
> 0.0
Description
Internal call cycle of the
PID controller for heating.
Rounded to an integer
multiple of the FB call
cycle time.
Deadband
"Retain.CtrlParams.
width(heatin Heat.DeadZone"
g) 2,3
Real
DeadZone>= 0.0
Width of the deadband
for heating control
deviation.
Control
Zone (heating)2,3
Real
ControlZone> 0.0
Width of the control
deviation zone for heating where PID control is
active. If control deviation leaves this range,
output is switched to
maximum output values.
"Retain.CtrlParams.
Heat.ControlZone"
Default value is
"MaxReal" so control
zone is deactivated as
long as autotuning is
not executed.
Value "0.0" is prohibited for Control Zone;
with the value "0.0",
PID_Temp behaves like
a two-position controller
that is always heating
or cooling at full power.
S7-1200 Programmable controller
646
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Setting
Controller
structure
(heating)
TO-DB parameter
"PIDSelfTune.SUT.
TuneRuleHeat",
Data
type
Int
"PIDSelfTune.TIR.
TuneRuleHeat"
Value range
"PIDSelfTune.SUT.
TuneRuleHeat"
= 0..2,
"PIDSelfTune.TIR.
TuneRuleHeat"
= 0..5
Description
You can select the
tuning algorithm for
heating.
Possible selections:
•
PID (Temperature)
(=default)
("PIDSelfTune.SUT.
TuneRuleHeat" = 2)
("PIDSelfTune.TIR.
TuneRuleHeat" = 0)
•
PID
("PIDSelfTune.SUT.
TuneRuleHeat" = 0)
("PIDSelfTune.TIR.
TuneRuleHeat" = 0)
•
PI
("PIDSelfTune.SUT.
TuneRuleHeat" = 1)
("PIDSelfTune.TIR.
TuneRuleHeat" = 4)
Any other combination
shows “User defined”,
but “User defined” is
not provided by default.
“PID (Temperature)” is
new for PID_Temp,
with a specific pretuning (SUT) method for
temperature processes.
Proportional "Retain.CtrlParams.
gain (coolCool.Gain"
ing) 4
Real
Gain >= 0.0
PID proportional gain
for cooling
Integral
action time
(cooling) 1,4
"Retain.CtrlParams.
Cool.Ti"
Real
100000.0 >=Ti
>= 0.0
PID integral action for
cooling
Derivative
action time
(cooling) 1,4
"Retain.CtrlParams.
Cool.Td"
Real
100000.0 >=Td
>= 0.0
PID derivative action
time for cooling
Real
TdFiltRatio>= 0.0
PID derivative delay
coefficient for cooling
that defines the derivative lag time as a coefficient from the PID
derivative time.
Derivative
Retain.CtrlParams.
delay coeffi- Cool.TdFiltRatio"
cient (cooling) 4
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
647
Technology instructions
10.2 PID control
Setting
TO-DB parameter
Proportional "Retain.CtrlParams.
action
Cool.PWeighting"
weighting
(cooling) 4
Data
type
Value range
Description
Real
1.0 >=PWeighting Weighting of the PID
>= 0.0
proportional gain for
cooling in either the
direct- or loopbackcontrol path.
Derivative
action
weighting
(cooling) 4
Retain.CtrlParams.
Cool.DWeighting"
Real
1.0 >=DWeighting Weighting of the PID
>= 0.0
derivative part for cooling in either the director loopback- control
path.
Sampling
time of PID
algorithm
(cooling) 1,4
"Retain.CtrlParams.
Cool.Cycle"
Real
100000.0
>=Cycle
> 0.0
Deadband
width (cooling) 3,4
"Retain.CtrlParams.
Cool.DeadZone"
Internal call cycle of the
PID controller for cooling.
Rounded to an integer
multiple of the FB call
cycle time.
Real
DeadZone>= 0.0
Width of the deadband
for cooling control deviation
S7-1200 Programmable controller
648
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Setting
Control
Zone (cooling) 3,4
TO-DB parameter
"Retain.CtrlParams.
Cool.ControlZone"
Data
type
Real
Value range
Description
ControlZone> 0.0
Width of the control
deviation zone for cooling where PID control is
active. If control deviation leaves this range,
output is switched to
maximum output values.
Default value is
"MaxReal" so control
zone is deactivated as
long as autotuning is
not executed.
Value "0.0" is prohibited for Control Zone;
with the value "0.0",
PID_Temp behaves like
a two-position controller
that is always heating
or cooling at full power.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
649
Technology instructions
10.2 PID control
Setting
Controller
structure
(cooling)
TO-DB parameter
"PIDSelfTune.SUT.
TuneRuleCool",
"PIDSelfTune.TIR.
TuneRuleCool"
Data
type
Int
Value range
"PIDSelfTune.SUT.
TuneRuleHeat"
= 0..2,
"PIDSelfTune.TIR.
TuneRuleHeat"
= 0..5
Description
You can select the
tuning algorithm for
cooling.
Possible selections:
•
PID (Temperature)
(=default)
("PIDSelfTune.SUT.
TuneRuleCool" = 2)
("PIDSelfTune.TIR.
TuneRuleCool = 0)
•
PID
("PIDSelfTune.SUT.
TuneRuleCool" = 0)
("PIDSelfTune.TIR.
TuneRuleCool" = 0)
•
PI
("PIDSelfTune.SUT.
TuneRuleCool" = 1)
("PIDSelfTune.TIR.
TuneRuleCool" = 4)
Any other combination
shows “User defined”,
but “User defined” is
not provided by default.
“PID (Temperature)” is
new for PID_Temp,
with a specific pretuning (SUT) method for
temperature processes.
Only available if you
check/select the following items: “Activate
output (cooling)” in
“Basic settings” view
("Config.ActivateCooling" =
TRUE), and “PID parameter switchover” in
“Output settings” view
(Config.AdvancedCooling =
TRUE).
S7-1200 Programmable controller
650
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.2 PID control
Setting
TO-DB parameter
Data
type
Value range
Description
1
The field displays "s" (seconds) as the time units.
2
Only available if you check "Enable manual entry” in PID parameters ("Retain.CtrlParams.SetByUser" = TRUE).
3
Unit of measurement is displayed at the end of the field as selected in “Basic settings” view.
4
Only available if you check/select the following items: "Enable manual entry” in PID parameters
("Retain.CtrlParams.SetByUser" = TRUE), “Activate output (cooling)” in “Basic settings” view
("Config.ActivateCooling" = TRUE), and “PID parameter switchover” in “Output settings” view
(Config.AdvancedCooling = TRUE).
PID start value control
You can edit the actual values of the PID configuration parameters so that the behavior of
the PID controller can be optimized in online mode.
Open the "Technology objects" for your PID controller and its "Configuration" object. To
access the start value control, click the "eyeglasses icon" in the upper left corner of the
dialog:
You can now change the value of any of your PID controller configuration parameters as
shown in the figure below.
You can compare the actual value to the project (offline) start value and the PLC (online)
start value of each parameter. This is necessary to compare online/offline differences of the
Technology object data block (TO-DB) and to be informed about the values that will be used
as current values on the next Stop-to-Start transition of the PLC. In addition, a compare icon
gives a visual indication to help easily identify online/offline differences:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
651
Technology instructions
10.2 PID control
The figure above shows the PID parameter screen with compare icons showing which
values are different between online and offline projects. A green icon indicates that the
values are the same; a blue/orange icon indicates that the values are different.
Additionally, click the parameter button with the downward arrow to open a small window
that shows the project (offline) start value and the PLC (online) start value of each
parameter:
S7-1200 Programmable controller
652
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3
Motion control
The CPU provides motion control functionality for the operation of stepper motors and servo
motors with pulse interface. The motion control functionality takes over the control and
monitoring of the drives.
● The "Axis" technology object configures the mechanical drive data, drive interface,
dynamic parameters, and other drive properties.
● You configure the pulse and direction outputs of the CPU for controlling the drive.
● Your user program uses the motion control instructions to control the axis and to initiate
motion tasks.
● Use the PROFINET interface to establish the online connection between the CPU and the
programming device. In addition to the online functions of the CPU, additional
commissioning and diagnostic functions are available for motion control.
Note
Changes that you make to the motion control configuration and download in RUN mode
do not take effect until the CPU transitions from STOP to RUN mode.
①
②
③
④
PROFINET
Pulse and direction outputs
Power section for stepper motor
Power section for servo motor
The DC/DC/DC variants of the CPU S7-1200 have onboard
outputs for direct control of drives. The relay variants of the
CPU require the signal board with DC outputs for drive control.
A signal board (SB) expands the onboard I/O to include a few additional I/O points. An SB
with two digital outputs can be used as pulse and direction outputs to control one motor. An
SB with four digital outputs can be used as pulse and direction outputs to control two motors.
Built-in relay outputs cannot be used as pulse outputs to control motors. Whether you use
onboard I/O or SB I/O or a combination of both, you can have a maximum number of four
pulse generators.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
653
Technology instructions
10.3 Motion control
The four pulse generators have default I/O assignments; however, they can be configured to
any digital output on the CPU or SB. Pulse generators on the CPU cannot be assigned to
SMs or to distributed I/O.
Note
Pulse-train outputs cannot be used by other instructions in the user program
When you configure the outputs of the CPU or signal board as pulse generators (for use with
the PWM or motion control instructions), the corresponding output addresses no longer
control the outputs. If your user program writes a value to an output used as a pulse
generator, the CPU does not write that value to the physical output.
Table 10- 35 Maximum number of controllable drives
Type of CPU
CPU 1211C
CPU 1212C
CPU 1214C
CPU 1215C
CPU 1217C
Onboard I/O;
No SB installed
With an SB
(2 x DC outputs)
With an SB
(4 x DC outputs)
With direction
Without
direction
With direction
Without
direction
With direction
Without
direction
DC/DC/DC
2
4
3
4
4
4
AC/DC/Relay
0
0
1
2
2
4
DC/DC/Relay
0
0
1
2
2
4
DC/DC/DC
3
4
3
4
4
4
AC/DC/Relay
0
0
1
2
2
4
DC/DC/Relay
0
0
1
2
2
4
DC/DC/DC
4
4
4
4
4
4
AC/DC/Relay
0
0
1
2
2
4
DC/DC/Relay
0
0
1
2
2
4
DC/DC/DC
4
4
4
4
4
4
AC/DC/Relay
0
0
1
2
2
4
DC/DC/Relay
0
0
1
2
2
4
DC/DC/DC
4
4
4
4
4
4
Note
The maximum number of pulse generators is four.
Whether you use onboard I/O, SB I/O, or a combination of both, you can have a maximum
number of four pulse generators.
S7-1200 Programmable controller
654
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 36 CPU output: maximum frequency
CPU
CPU output channel
Pulse and direction
output
A/B, quadrature, up/down,
and pulse/direction
1211C
Qa.0 to Qa.3
100 kHz
100 kHz
1212C
Qa.0 to Qa.3
100 kHz
100 kHz
Qa.4, Qa.5
20 kHz
20 kHz
Qa.0 to Qa.3
100kHz
100kHz
Qa.4 to Qb.1
20 kHz
20 kHz
DQa.0 to DQa.3
1 MHz
1 MHz
100 kHz
100 kHz
1214C and 1215C
1217C
(.0+, .0- to .3+, .3-)
DQa.4 to DQb.1
Table 10- 37 SB signal board output: maximum frequency (optional board)
SB signal board
SB output channel
Pulse and direction
output
A/B, quadrature, up/down,
and pulse/direction
SB 1222, 200 kHz
DQe.0 to DQe.3
200kHz
200 kHz
SB 1223, 200 kHz
DQe.0, DQe.1
200kHz
200 kHz
SB 1223
DQe.0, DQe.1
20 kHz
20 kHz
Table 10- 38 Limit frequencies of pulse outputs
Pulse output
Frequency
Onboard
4 PTO: 2 Hz ≤ f ≤ 1 MHz, 4 PTO: 2 Hz ≤ f ≤ 100 kHz, or any
combination of these values for 4 PTOs.1 2
Standard SB
2 Hz ≤ f ≤ 20 kHz
High-speed SBs
2 Hz ≤ f ≤ 200 kHz
1
See the table below for four possible CPU 1217C output speed combinations.
2
See the table below for four possible CPU 1211C, CPU 1212C, CPU 1214C, or CPU 1215C output
speed combinations.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
655
Technology instructions
10.3 Motion control
Example: CPU 1217C pulse output speed configurations
Note
The CPU 1217C can generate pulse outputs up to 1 MHz, using the onboard differential
outputs.
The examples below show four possible output speed combinations:
● Example 1: 4 - 1 MHz PTOs, no direction output
● Example 2: 1 - 1 MHz, 2 - 100 kHz, and 1 - 20 kHz PTOs, all with direction output
● Example 3: 4 - 200 kHz PTOs, no direction output
● Example 4: 2 - 100 kHz PTOs and 2 - 200 kHz PTOs, all with direction output
P = Pulse
CPU on-board outputs
High-speed SB outputs
Standard
SB outputs
200 kHz Outputs (Q)
20 kHz
Outputs
(Q)
D = Direction
1 MHz Outputs (Q)
Ex. 1:
4-1
MHz
(no
direction
output)
PTO1
Ex. 2: 1 1 MHz; 2
- 100
and 1 20 kHz
(all with
direction
output)
PTO1
Ex. 3:
4 - 200
kHz (no
direction
output)
PTO1
Ex. 4:
2 - 100
kHz;
2 - 200
kHz (all
with
direction
output)
PTO1
0.0+ 0.1+
0.2+
0.3+
0.0-
0.2-
0.3-
0.1-
0.4
0.5
P
D
0.6
0.7
P
D
1.0
1.1
4.0
4.1
4.2
4.3
D
P
P
D
PTO3
PTO4
P
PTO2
P
PTO3
P
PTO4
PTO4
P
P
PTO4
PTO3
4.1
P
PTO3
PTO2
4.0
P
PTO2
PTO2
100 kHz Outputs (Q)
P
P
D
P
D
P
D
P
D
S7-1200 Programmable controller
656
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: CPU 1211C, CPU 1212C, CPU 1214C, and CPU 1215C pulse output speed configurations
The examples below show four possible output speed combinations:
● Example 1: 4 - 100 kHz PTOs, no direction output
● Example 2: 2 - 100 kHz PTOs and 2 - 20 kHz PTOs, all with direction output
● Example 3: 4 - 200 kHz PTOs, no direction output
● Example 4: 2 - 100 kHz PTOs and 2 - 200 kHz PTOs, all with direction output
P = Pulse
CPU on-board outputs
High-speed SB outputs
Low-speed
SB outputs
200 kHz Outputs (Q)
20 kHz
Outputs
(Q)
D = Direction
100 kHz Outputs (Q)
0.0
0.1
0.2
0.3
20 kHz Outputs (Q)
0.4
0.5
0.6
0.7
1.0
1.1
4.0
4.1
4.2
4.3
4.0
4.1
CPU 1211C
Ex. 1:
4 - 100
kHz (no
direction
output)
PTO1
Ex. 2:
2 - 100
kHz;
2 - 20
kHz (all
with direction output)
PTO1
Ex. 3:
4 - 200
kHz (no
direction
output)
PTO1
Ex. 4:
2 - 100
kHz;
2 - 200
kHz (all
with direction output)
PTO1
CPU 1212C
CPU
1212C
CPU 1214C
CPU
1214C
CPU 1214C
CPU 1215C
CPU
1215C
CPU 1215C
P
PTO2
P
PTO3
P
PTO4
P
P
D
PTO2
P
D
PTO3
P
PTO4
D
P
D
P
PTO2
P
PTO3
P
PTO4
P
P
PTO2
D
P
D
PTO3
PTO4
P
D
P
D
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
657
Technology instructions
10.3 Motion control
Note
Refer to the SIMATIC STEP 7 S7-1200 Motion Control V14 Function Manual for further
information.
10.3.1
Phasing
You have four options for the "Phasing" interface to the stepper/servo drive. These options
are as follows:
● PTO (pulse A and direction B): If you select a PTO (pulse A and direction B) option, then
one output (P0) controls the pulsing and one output (P1) controls the direction. P1 is high
(active) if pulsing is in the positive direction. P1 is low (inactive) if pulsing is in the
negative direction:
● PTO (pulse up A and pulse down B): If you select a PTO (pulse up A and pulse down B)
option, then one output (P0) pulses for positive directions and a different output (P1)
pulses for negative directions:
S7-1200 Programmable controller
658
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
● PTO (A/B phase-shifted): If you select a PTO (A/B phase-shifted) option, then both
outputs pulse at the speed specified, but 90 degrees out-of-phase. It is a 1X
configuration, meaning one pulse is the amount of time between positive transitions of
P0. In this case, the direction is determined by which output transitions high first. P0
leads P1 for the positive direction. P1 leads P0 for the negative direction.
The number of pulses generated is based upon the number of 0 to 1 transitions of Phase
A. The phase relationship determines the direction of movement:
PTO (A/B phase-shifted)
Phase A leads phase B (positive movement)
Phase A lags phase B (negative movement)
Number of pulses
Number of pulses
● PTO (A/B phase-shifted - fourfold): If you select a PTO (A/B phase-shifted - fourfold)
option, then both outputs pulse at the speed specified, but 90 degrees out-of-phase. The
fourfold is a 4X configuration, meaning one pulse is the transition of each output (both
positive and negative). In this case, the direction is determined by which output
transitions high first. P0 leads P1 for the positive direction. P1 leads P0 for the negative
direction.
Fourfold is based upon positive and negative transitions of both Phase A and Phase B.
You configure the number of transitions. The phase relationship (A leading B or B leading
A) determines the direction of movement.
PTO (A/B phase-shifted - fourfold)
Phase A leads phase B (positive movement)
Phase A lags phase B (negative movement)
Number of pulses
Number of pulses
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
659
Technology instructions
10.3 Motion control
● PTO (pulse and direction (direction de-selected)): If you de-select the direction output in a
PTO (pulse and direction (direction de-selected)), then output (P0) controls the pulsing.
Output P1 is not used and is available for other program uses. Only positive motion
commands are accepted by the CPU in this mode. Motion control restricts you from
making illegal negative configurations when you select this mode. You can save an
output if your motion application is in one direction only. Single phase (one output) is
shown in the figure below (assuming positive polarity):
S7-1200 Programmable controller
660
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.2
Configuring a pulse generator
1. Add a Technology object:
– In the Project tree, expand the node "Technology Objects" and select "Add new
object".
– Select the "Axis" icon (rename if required) and click "OK" to open the configuration
editor for the axis object.
Note
To ensure the consistency of your project after you rename the technology objects,
download the project to the CPU while it is in STOP. A name change occurs when you
delete a technolology object and create a new technology object with a new name and
data block number.
– Display the "Select PTO for Axis Control" properties under the "Basic parameters" and
select the desired pulse.
Note
If the PTO has not been previously configured in the CPU Properties, the PTO is
configured to use one of the onboard outputs.
If you use an output signal board, then select the "Device configuration" button to go
to the CPU Properties. Under "Parameter assignment", in the "Pulse options",
configure the output source to a signal board output.
– Configure the remaining Basic and Extended parameters.
2. Program your application: Insert the MC_Power instruction in a code block.
– For the Axis input, select the axis technology object that you created and configured.
– Setting the Enable input to TRUE allows the other motion instructions to function.
– Setting the Enable input FALSE cancels the other motion instructions.
Note
Include only one MC_Power instruction per axis.
3. Insert the other motion instructions to produce the required motion.
Note
Configuring a pulse generator to signal board outputs: Select the "Pulse generators
(PTO/PWM)" properties for a CPU (in Device configuration) and enable a pulse generator.
Two pulse generators are available for each S7-1200 CPU V1.0, V2.0, V2.1, and V2.2.
S7-1200 CPU V3.0 and V4.0 CPUs have four pulse generators available. In this same
configuration area under "Pulse options", select Pulse generator used as: "PTO".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
661
Technology instructions
10.3 Motion control
Note
The CPU calculates motion tasks in "slices" or segments of 10 ms. As one slice is being
executed, the next slice is waiting in the queue to be executed. If you interrupt the motion
task on an axis (by executing another new motion task for that axis), the new motion task
cannot be executed for a maximum of 20 ms (the remainder of the current slice plus the
queued slice).
10.3.3
Open loop motion control
10.3.3.1
Configuring the axis
You connect the open loop axis on the PLC and the drive through a PTO (Pulse Train
Output). For motion applications using PTO, the CPU requires onboard or signal board (SB)
digital I/O. This limits the number of axes that are available on the smaller PLCs.
STEP 7 provides the configuration tools, the commissioning tools, and the diagnostic tools
for the "Axis" technology object.
①
②
③
Drive
Technology object
④
⑤
Commissioning
Diagnostics
Configuration
Note
For CPU firmware releases V2.2 and earlier, the PTO requires the internal functionality of a
high-speed counter (HSC). This means the corresponding HSC cannot be used elsewhere.
The assignment between PTO and HSC is fixed. If PTO1 is activated, it will be connected to
HSC1. If PTO2 is activated, it will be connected to HSC2. You cannot monitor the current
value (for example, in ID1000) when pulses are occurring.
S7-1200 V3.0 and later CPUs do not have this restriction; all HSCs remain available for
program use when pulse outputs are configured in these CPUs.
S7-1200 Programmable controller
662
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 39 STEP 7 tools for motion control
Tool
Description
Configuration
Configures the following properties of the "Axis" technology object:
•
Selection of the PTO to be used and configuration of the drive interface
•
Properties of the mechanics and the transmission ratio of the drive (or machine or system)
• Properties for position limits, dynamics, and homing
Save the configuration in the data block of the technology object.
Commissioning
Tests the function of your axis without having to create a user program. When the tool is started,
the control panel will be displayed. The following commands are available on the control panel:
•
Enable and disable axis
•
Move axis in jog mode
•
Position axis in absolute and relative terms
•
Home axis
• Acknowledge errors
The velocity and the acceleration / deceleration can be specified for the motion commands. The
control panel also shows the current axis status.
Diagnostics
Monitors of the current status and error information for the axis and drive.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
663
Technology instructions
10.3 Motion control
The tree selector for the PTO axis does not include
the Encoder, Modulo, Position monitoring, and
Control loop configuration menus.
After you create the technology object for the axis,
you configure the axis by defining the basic parameters, such as the PTO and the configuration of
the drive interface. You also configure the other
properties of the axis, such as position limits, dynamics, and homing.
Note
You may have to adapt the values of the input parameters of motion control instructions to
the new dimension unit in the user program.
S7-1200 Programmable controller
664
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Configure the properties for the drive signals, drive
mechanics, and position monitoring (hardware and
software limit switches).
You configure the motion dynamics and the behavior of the emergency stop command.
You also configure the homing behavior (passive and active).
Use the "Commissioning" control panel to test the functionality independently from your user
program.
Click the "Startup" icon to commission the axis.
The control panel shows the current status of the axis. Not only can you enable and disable
the axis, but you can also test the positioning of the axis (both in absolute and relative terms)
and can specify the velocity, acceleration and deceleration. You can also test the homing
and jogging tasks. The control panel also allows you to acknowledge errors.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
665
Technology instructions
10.3 Motion control
10.3.3.2
Commissioning
"Status and error bits" diagnostic function
Use the "Status and error bits" diagnostic function to monitor the most important status and
error messages for the axis. The diagnostic function display is available in online mode in
"Manual control" mode and in "Automatic control" when the axis is active.
Table 10- 40 Status of the axis
Status
Enabled
Description
The axis is enabled and ready to be controlled via motion control tasks.
(Tag of technology object: .StatusBits.Enable)
Homed
The axis is homed and is capable of executing absolute positioning tasks of motion control instruction "MC_MoveAbsolute". The axis does not have to be homed for relative homing. Special situations:
•
During active homing, the status is FALSE.
• If a homed axis undergoes passive homing, the status is set to TRUE during passive homing.
(Tag of technology object: .StatusBits.HomingDone)
Error
An error has occurred in the "Axis" technology object. More information about the error is available
in automatic control at the ErrorID and ErrorInfo parameters of the motion control instructions. In
manual mode, the "Last error" field of the control panel displays detailed information about the
cause of error.
(Tag of technology object: .StatusBits.Error)
Control panel active
The "Manual control" mode was enabled in the control panel. The control panel has control priority
over the "Axis" technology object. The axis cannot be controlled from the user program.
(Tag of technology object: .StatusBits.ControlPanelActive)
Table 10- 41 Drive status
Status
Description
Drive ready
The drive is ready for operation.
(Tag of technology object: .StatusBits.DriveReady)
Error
The drive has reported an error after failure of its ready signal.
(Tag of technology object: .ErrorBits.DriveFault)
S7-1200 Programmable controller
666
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 42 Status of the axis motion
Status
Description
Standstill
The axis is at a standstill.
(Tag of technology object: .StatusBits.StandStill)
Accelerating
The axis accelerates.
(Tag of technology object: .StatusBits.Acceleration)
Constant velocity
The axis travels at constant velocity.
(Tag of technology object: .StatusBits.ConstantVelocity)
Decelerating
The axis decelerates (slows down).
(Tag of technology object: .StatusBits.Deceleration)
Table 10- 43 Status of the motion mode
Status
Description
Positioning
The axis executes a positioning task of motion control instruction "MC_MoveAbsolute" or
"MC_MoveRelative" or of the control panel.
(Tag of technology object: .StatusBits.PositioningCommand)
Speed Command
The axis executes a task at set speed of motion control instruction "MC_MoveVelocity" or
"MC_MoveJog" or of the control panel.
(Tag of technology object: .StatusBits.SpeedCommand)
Homing
The axis executes a homing task of motion control instruction "MC_Home" or the control
panel.
(Tag of technology object: .StatusBits.Homing)
Table 10- 44 Error bits
Error
Description
Min software limit reached
The lower software limit switch has been reached.
(Tag of technology object: .ErrorBits.SwLimitMinReached)
Min software limit exceeded
The lower software limit switch has been exceeded.
(Tag of technology object: .ErrorBits.SwLimitMinExceeded)
Max software limit reached
The upper software limit switch has been reached.
(Tag of technology object: .ErrorBits.SwLimitMaxReached)
Max software limit exceeded
The upper software limit switch has been exceeded.
(Tag of technology object: .ErrorBits.SwLimitMaxExceeded)
Negative hardware limit
The lower hardware limit switch has been approached.
(Tag of technology object: .ErrorBits.HwLimitMin)
Positive hardware limit
The upper hardware limit switch has been approached.
(Tag of technology object: .ErrorBits.HwLimitMax)
PTO already used
A second axis is using the same PTO and is enabled with "MC_Power".
(Tag of technology object: .ErrorBits.HwUsed)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
667
Technology instructions
10.3 Motion control
Error
Description
Configuration error
The "Axis" technology object was incorrectly configured or editable configuration data
were modified incorrectly during runtime of the user program.
(Tag of technology object: .ErrorBits.ConfigFault)
General Error
An internal error has occurred.
(Tag of technology object: .ErrorBits.SystemFault)
"Motion status" diagnostic function
Use the "Motion status" diagnostic function to monitor the motion status of the axis. The
diagnostic function display is available in online mode in "Manual control" mode and in
"Automatic control" when the axis is active.
Table 10- 45 Motion status
Status
Description
Target position
The "Target position" field indicates the current target position of an active positioning task of
motion control instruction "MC_MoveAbsolute" or "MC_MoveRelative" or of the control panel.
The value of the "Target position" is only valid during execution of a positioning task.
(Tag of technology object: .MotionStatus.TargetPosition)
Current position
The "Current position" field indicates the current axis position. If the axis is not homed, the
value indicates the position value relative to the enable position of the axis.
(Tag of technology object: .MotionStatus.Position)
Current velocity
The "Current velocity" field indicates the actual axis velocity.
(Tag of technology object: .MotionStatus.Velocity)
Table 10- 46 Dynamic limits
Dynamic limit
Description
Velocity
The "Velocity" field indicates the configured maximum velocity of the axis.
(Tag of technology object: .Config.DynamicLimits.MaxVelocity)
Acceleration
The "Acceleration" field indicates the currently configured acceleration of the axis.
(Tag of technology object: .Config.DynamicDefaults.Acceleration)
Deceleration
The "Deceleration" field indicates the currently configured deceleration of the axis.
(Tag of technology object: .Config.DynamicDefaults.Deceleration)
S7-1200 Programmable controller
668
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Motion start value control
You can edit the actual values of the Motion configuration parameters so that the behavior of
the process can be optimized in online mode.
Open the "Technology objects" for your motion control and its "Configuration" object. To
access the start value control, click the "eyeglasses icon" in the upper left corner of the
dialog:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
669
Technology instructions
10.3 Motion control
You can now change the value of any of your motion control configuration parameters as
shown in the figure below.
You can compare the actual value to the project (offline) start value and the PLC (online)
start value of each parameter. This is necessary to compare online/offline differences of the
Technology object data block (TO-DB) and to be informed about the values that will be used
as current values on the next Stop-to-Start transition of the PLC. In addition, a compare icon
gives a visual indication to help easily identify online/offline differences.
The figure above shows the Motion parameter screen with compare icons showing which
values are different between online and offline projects. A green icon indicates that the
values are the same; a blue/orange icon indicates that the values are different.
S7-1200 Programmable controller
670
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Additionally, click the parameter button with the downward arrow to open a small window
that shows the project (offline) start value and the PLC (online) start value of each
parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
671
Technology instructions
10.3 Motion control
10.3.4
Closed loop motion control
10.3.4.1
Configuring the axis
You connect the closed loop axis on the PLC and the drive through one of two connections:
● Analog drive: This connection can use onboard, SB, or signal module (SM) analog I/O; it
does not use PTOs. You have the following analog I/O resolution available for your
application:
– Onboard I/O: 10 bit (lowest I/O resolution)
– Signal board (SB) I/O: 12 bit
– SM I/O: 14 bit (highest I/O resolution)
● PROFIdrive: This connection is a network solution and does not use PTOs.
The closed loop axis requires an encoder as well. You can connect encoders to the following
items:
● Encoder interface on the drive
● High-speed counters (HSC)
● Technology modules (TM)
● PROFIdrive encoder on PROFINET / PROFIBUS
You can have a maximum number of eight drives (or axes) for the PROFIdrive or analog
drive connection.
STEP 7 provides the configuration tools, the commissioning tools, and the diagnostic tools
for the "Axis" technology object.
①
②
③
Drive
Technology object
④
⑤
Commissioning
Diagnostics
Configuration
S7-1200 Programmable controller
672
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 47 STEP 7 tools for closed loop motion control
Tool
Configuration
Description
Configures the following properties of the "Axis" technology object:
•
Selection of the analog drive connection or PROFIdrive to be used and configuration of the
drive and encoder interface
•
Properties of the mechanics and the transmission ratio of the drive and encoder (or machine
or system)
• Properties for position limits, dynamics, and homing
Save the configuration in the data block of the technology object.
Commissioning
Tests the function of your axis without having to create a user program. When the tool is started,
the control panel will be displayed. The following commands are available on the control panel:
•
Enable and disable axis
•
Move axis in jog mode
•
Position axis in absolute and relative terms
•
Home axis
• Acknowledge errors
The velocity and the acceleration / deceleration can be specified for the motion commands. The
control panel also shows the current axis status.
Diagnostics
Monitors of the current status and error information for the axis and drive.
Note
You may have to adapt the values of the input parameters of motion control instructions to
the new dimension unit in the user program.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
673
Technology instructions
10.3 Motion control
After you create the technology object for the axis, you configure the axis by defining the
basic parameters, either the Analog drive or the PROFIdrive connection and the
configuration of the drive and encoder.
The tree selector for the analog drive or
PROFIdrive connection includes the Encoder,
Modulo, Position monitoring, and Control loop configuration menus.
S7-1200 Programmable controller
674
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Analog drive connection configuration
In the General configuration dialog, you select the
following parameters:
• "Analog drive connection" radio button
• Unit of measurement
In the Drive configuration dialog, you select the
following parameters:
• Analog drive hardware outputs
• Data exchange drive velocities
Note: The Maximum speed must be greater
than or equal to the Reference (nominal) speed.
In the Encoder configuration dialog, you select the
following parameters:
• Analog drive encoder coupling (for example, a
high-speed counter (HSC))
• HSC interface
• Encoder type
• Fine resolution
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
675
Technology instructions
10.3 Motion control
PROFIdrive configuration
In the General configuration dialog, you select the
following parameters:
• "PROFIdrive" radio button
• Unit of measurement
In the Drive configuration dialog, you select the
following parameters:
• PROFIdrive drive
• Data exchange with the drive
Note: The Maximum speed must be greater
than or equal to the Reference (nominal) speed.
In the Encoder configuration dialog, you select the
following parameters:
• PROFIdrive encoder coupling (for example, a
PROFIdrive encoder on PROFINET)
• PROFIdrive encoder
• Data exchange with the encoder
• Encoder type
• Fine resolution
S7-1200 Programmable controller
676
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Extended parameters
You can also configure the following properties of the closed loop axis:
● Modulo
● Position limits
● Dynamics
● Homing
● Position monitoring
● Following error
● Standstill signal
● Control loop
Modulo: You can configure a "Modulo" axis to
move the load in a cyclic area which has a start
value/start position and a given length. If the position of the load reaches the end of this area, it is
automatically set to the start value again. You enable the "Length" and "Modulo start value" fields
when you check the "Enable Modulo" check box.
Position limits: You can configure the properties for
the drive signals, drive mechanics, and position
monitoring (hardware and software limit switches).
Dynamics: You can configure the motion dynamics
and the behavior of the emergency stop command.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
677
Technology instructions
10.3 Motion control
Homing: You can configure the homing behavior (passive and active).
"Positioning monitoring": You can configure
tolerance time as well as minimum dwell
time for the positioning window.
The system connects the following three
parameters directly with the axis TO-DB:
• Positioning window
• Tolerance time
• Minimum dwell time in positioning window
Note: The "Positioning window" field's minimum value is "0.001" and its maximum value
is "1 E+12".
"Following error": You can configure the
difference of the allowed error distance over
a velocity range. You check the "Enable
following error monitoring" check box to activate following error. You can configure the
following parameters:
• Maximum following error
• Following error
• Start dynamic adjustment
• Maximum velocity
S7-1200 Programmable controller
678
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
"Standstill signal": You can configure the
following parameters:
• Minimum dwell time in standstill window
• Standstill window.
"Control loop": You can configure the velocity gain known as "Precontrol (Kv factor)".
Use the "Commissioning" control panel to test the functionality independently from your user
program.
Click the "Startup" icon to commission the axis.
The control panel shows the current status of the axis. Not only can you enable and disable
the axis, but you can also test the positioning of the axis (both in absolute and relative terms)
and can specify the velocity, acceleration and deceleration. You can also test the homing
and jogging tasks. The control panel also allows you to acknowledge errors.
10.3.4.2
ServoOBs
When you create a technology object for S7-1200 motion control, the CPU automatically
creates the organization block "MC-Servo (OB 91)" for processing the technology objects.
The motion control functionality of the technology objects creates its own priority class, and
the SIMATIC S7-1200 execution system calls the OB according to the application cycle.
The MC-Servo OB is write-protected. You cannot change the contents.
The position control algorithms of all technology objects configured for motion control on the
CPU are calculated within the MC-Servo OB.
You can set the application cycle and the priority of the organization block in accordance
with your requirements for control quality and system load. Multiple ServoOBs can link to a
"CyclicServoEvent". The Property page of the MC-Servo OB shows the two changeable
values of the CyclicServoEvent:
● Priority number
● Cycle time
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
679
Technology instructions
10.3 Motion control
The MC-PreServo OB and MC-PostServo OB are instances of the ServoOB, and they are of
type ServoOB. These OBs are optional, can only exist if MC-Servo OB is present, and
contain user code. All three OBs (MC-PreServo, MC-Servo, and MC-PostServo) have to run
in the same runtime level, and the same CyclicServoEvent triggers them. The PLC firmware
executes the OBs sequencially, based upon their block number:
OB instance
OB number
Automation System
Object Model (ASOM)
event
Engineering System
Object Model (ESOM)
event
MC-PreServo
67
ServoOB
-
MC-Servo
91
ServoOB
ServoOB
MC-PostServo
95
ServoOB
-
Compared to the ASOM, the Engineering System Object Model (ESOM) only links the event
to the MC-Servo OB. The ESOM does not link the event to the MC-PreServo OB or MCPostServo OB.
Configuring the axis with an application cycle MC-Servo (OB 91)
Application cycle MC-Servo (OB 91)
You can set the application cycle in which the MC-Servo OB is called in the properties of the
organization block:
● Synchronous to the BUS: You call the MC-Servo OB synchronously with a bus system.
You set the send clock in the properties of the selected bus system.
● Cyclical: You call the MC-Servo OB cyclically with the assigned application cycle.
To avoid disruptions in the program execution on the CPU, set the application cycle
depending on the number of used axes as follows:
Application cycle = number of axes x 2 ms
Number of axes
Application cycle
1
2 ms
2
4 ms
4
8 ms
8
16 ms
The SINAMICS G120 drive updates the drive process image every 4 ms. To improve control,
set the application cycle of the MC-Servo (OB 91) to 4 ms or to a multiple of 4 ms.
S7-1200 Programmable controller
680
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Overflow MC-Servo (OB 91)
The selected application cycle must be long enough to allow all the technology objects for
motion control to be processed in one cycle. If the application cycle is not observed,
overflows occur.
The CPU does not go into STOP at overflow of the MC-Servo (OB 91). (The TIA Portal
online help statement concerning STOP at overflow of the MC-Servo (OB 91) is incorrect.)
If necessary, you can set the CPU to STOP at overflow of the MC-Servo (OB 91) using a
time-error OB (OB 80).
Process image partition OB Servo PIP
For optimal control of all I/O modules (for example, hardware limit switches) used by motion
control, assign them to the process image partition "OB Servo PIP". The assignment causes
the I/O modules to be processed simultaneously with the technology object.
When motion control uses a high-speed counter (HSC), motion control automatically assigns
the HSC to the process image partition "OB Servo PIP".
10.3.4.3
Speed controlled operation
With speed controlled operation, you can move a positioning axis with "speed controlled".
Using the MC_Power instruction, you can enable the axis. With the MC_MoveVelocity and
MC_MoveJog instructions, you can move the axis with velocity setpoints. You can move the
axis in spite of a sensor error even if no valid actual values are available. "Speed controlled"
mode sets the following conditions:
● Disables the positioning controller of the axis
● Sets velocity setpoints to the drive directly
● Sets the axis position setpoint to zero
● Updates the actual position of the axis in case of valid sensor values
● Does not define the following error and controller error and sets them to zero
You can activate and deactivate the "speed controlled" mode with the following three
instructions and these parameters:
● MC_Power.StartMode (Int)
● MC_MoveVelocity.PositionControlled (Bool)
● MC_MoveJog.PositionControlled (Bool)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
681
Technology instructions
10.3 Motion control
MC_Power
With the MC_Power instruction, you can enable the axis with the "speed controlled" mode.
You can do this if no valid sensor values are available or the axis cannot change to "position
controlled" mode.
You can only use StartModes "0" and "1". Other values show an error:
StartMode
PTO axis
Servo axis
0
Ignored
Speed controlled
1
Ignored
Positioning controlled
Other
Invalid mode
MC_Power.ErrorID = 0x8412
MC_Power.ErrorID = 0x0011
Invalid mode
MC_Power.ErrorID = 0x8412
MC_Power.ErrorID = 0x0011
During disabling of the TO axis with "MC_Power.Enable = FALSE", you obtain the operation
mode. Depending on the operation mode, the axis reacts with a different behavior:
StartMode
Mode: Position controlled
Mode: Speed controlled
0: Emergency stop
The axis decelerates positioning
controlled with "DynamicDefaults.
EmergencyDeceleration" based
upon the ActualPosition and
ActualVelocity.
The axis decelerates speed
controlled with "DynamicDefaults.
EmergencyDeceleration" based
upon the ActualVelocity if available.
1: Immediate stop
The drive stops with the "AUS3" The drive stops with the "AUS3"
ramp within the connected drive. ramp within the connected drive.
2: Emergency stop with jerk
control
Axis brakes are positioning
controlled at the configured
emergency deceleration based
upon the setpoint position. If the
jerk control is activated, the
configured jerk is taken into
account.
Axis brakes are speed controlled at the configured emergency deceleration based upon
the setpoint velocity. If the jerk
control is activated, the configured jerk is taken into account.
During drive switch off, the operation mode cannot be changed because new motion
commands are not accepted until the drive is stopped. After standstill of the drive, the axis
can be enabled again.
MC_MoveVelocity/MC_MoveJog
Independent of operation mode (Speed controlled / Positioning controlled), the blocks
change the axis to the configured mode. This can happen during closed loop motion or
during standstill.
MC_Halt
The MC_Halt instruction does not change the operation mode. In speed controlled mode, the
calculated deceleration ramp depends on the setpoint velocity with the configured
deceleration.
If the Standstill window is reached, the command is finished and shows "Done = TRUE".
S7-1200 Programmable controller
682
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Other motion commands
The speed controlled mode remains active until one of the following commands becomes
active:
● MC_MoveAbsolute
● MC_MoveRelative
● MC_MoveVelocity (PositionControlled = TRUE)
● MC_MoveJog (PositionControlled = TRUE)
● MC_Home:
– Active homing (Mode 3)
– Other modes (passive, direct, adjustment of absolute value sensor) are refused with
ErrorId:
ErrorId 8207: "Command rejected" / "Auftrag abgewiesen"
ErrorInfo 006B: "Aufruf im Speed controlled Mode unzulässig".
Axis TODB
The axis TODB displays the operation mode if one of the three motion instructions,
MC_Power, MC_MoveVelocity, or MC_MoveJog, are executed with the speed controlled
operation mode:
● Axis.Statusbit.NonPositionControlled = TRUE
● Axis.Position = 0.0
Calculation of new setpoint position
The setpoint position must be recalculated after a mode change from speed-controlled to
closed loop during motion:
● With Precontrol (kpc > 0): Position = ActualPosition + ActualVelocity * vtc
● Without Precontrol (kpc = 0): Position = ActualPosition + ActualVelocity / kv (vtc =
substitute time constate of precontrol; kv = gain of position control)
Software limit switches
During speed controlled mode, the software limit switches are not active.
Hardware limit switches
Hardware limit switches are supported during speed controlled mode.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
683
Technology instructions
10.3 Motion control
10.3.4.4
Telegram 4 support
The PROFdrive Telegram 4 contains actor values and two values from different encoders.
The first sensor value comes from the encoder on the motor. The second sensor value is
provided by an additional encoder on the machine.
The machine encoder is connected directly to a SINAMICS CU, and the CU provides both
sensor values within the Telegram 4.
Axis Drive configuration dialog
You configure Telegram 4 in the hardware configuration, and you can select it in the axis
Drive configuration dialog.
Axis Encoder configuration dialog
In the axis Encoder configuration dialog, you have two options:
● Encoder on PROFINET/PROFIBUS
● Encoder on high-speed counter (HSC)
"Encoder on PROFINET/PROFIBUS" is the default selection; however, both options are
available.
S7-1200 Programmable controller
684
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: Configuring the SINAMICS S120 and encoder with Telegram 4
1. Selecting the SINAMICS drive:
Use the hardware catalog to add a SINAMICS S120 CU310-2 PN V4.7 drive. To do so,
expand the following containers:
– Other field devices
– PROFINET IO
– Drives
– SIEMENS AG
– SINAMICS
Insert the drive as shown in the figures below:
Configure your PROFINET network.
2. Selecting the DO SERVO:
– From the Network view, double-click the SINAMICS S120 CU310-2 PN V4.7 drive.
– Open the Device overview.
– In the hardware catalog, expand the Module container.
– Double-click or drag the DO SERVO drive object to insert it in the first blank row:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
685
Technology instructions
10.3 Motion control
3. Selecting the Telegram 4:
– In the hardware catalog, expand the Submodules container.
– Double-click or drag the "Standard telegram 4, PZD-6/15;SERVO" to insert it in the
second blank row.
– You must skip a blank row to insert the Telegram 4, as shown in the figure below:
S7-1200 Programmable controller
686
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
4. Selecting the encoder in the Drive configuration dialog:
– Navigate to the axis configuration dialog, and the Basic parameters, Drive
configuration dialog.
– Move to the Select PROFIdrive drive, Drive: field.
– Click the ellipsis button.
– Double-click "PROFINET IO-System" to open its folder.
– Click "SINAMICS-S120-CU310-2PN".
– In the right pane, "DO SERVO_1: Standard telegam 4, PZD-6/14; SERVO" displays.
– Click the green check mark button to enter the configuration.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
687
Technology instructions
10.3 Motion control
5. Configuring the encoder:
– Since you selected Telegram 4 in the axis Drive configuration dialog, the Encoder
drive configuration dialog provides a new "Encoder in telegram" entry in the navigation
tree. When you select the "Encoder in telegram" entry, the right pane displays two
entries, Encoder 1 and Encoder 2, with encoder values.
– Motion control assigns one of the encoders as the drive encoder and the other
encoder as the machine encoder. When you select either Encoder 1 or Encoder 2,
you determine which encoder is assigned as the drive encoder. The encoder that you
do not select is assigned as the machine encoder.
– After you select the drive encoder, click the green check mark button to enter the
configuration:
S7-1200 Programmable controller
688
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.4.5
Simulation axis
You use Simulation Mode when you want to work with the PROFIdrive or the Analog drive
axis on a PLC without a connected drive.
Simulation Mode is required when you want to do one of the following tasks:
● Commisioning of program sequence without a drive
● Testing of user program without moving an axis
● Simulation of behavior of the axis using a process model without a real movement.
● Drive and encoder must not be connected: Testing is also possible without a projected
drive; drive will be added and configured later.
Configuring Simulation Mode
The following options are available:
TODB value
Dialog entries
Comment
0
No simulation
No simulation
1
Simulate drive and encoder
Simulation with and without
correct configured addresses of
the axis and configured I/O in
hardware configuration
You can only use Simulation Mode with Servo Axis, and, therefore, only with PROFIdrive
and Analog drive. In the case of a PTO axis, the simulation mode is "0".
The TIA Portal has to implement the remainder of the Simulation Mode in case of switching
the type of the axis to PTO. Also, with "Data adaptation", check that in the case of PTO that
simulation mode is "0", and, if not, it is set automatically.
The user selects the different simulation modes in the Basic parameters dialog > General
section > Simulation field as shown in the following figure:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
689
Technology instructions
10.3 Motion control
Mode 1: "Simulate drive and encoder":
● In this mode, the axis in your program executes and works on a PLC without real
connected hardware regarding a PROFIdrive drive and sensor.
● You do not require the logical I/O addresses in the Technology Objects data block
(TODB). This means that you do not have to configure the sensor and drive configuration
and additional digital signals (hardware limit switches and reference point switches) in the
TO and in hardware configuration. The axis does not supply data to the logical addresses
of sensor and drive.
● Simulates TODB ActualSpeed.
● Does not use the PROFIdrive telegram in the case of PROFIdrive.
● In the case of PROFIdrive, the PLC shows a diagnostic error that the configured
hardware (peripheral devices or drives) is missing, but this has no influence on the
applicability of the axis.
● Creates homing reports in all homing modes directly. Sets positions and status,
accordingly. Does not detect hardware inputs.
● All connections can be empty.
● Axis Control Panel \ Tuning Panel works as usual.
● Supports Speed Controlled axis.
● Does not support a virtual axis (like defined by SMC); however, you can use a simulated
axis with no hardware connections like a virtual axis.
Download case:
You can download the axis with changed simulation mode during PLC in RUN. In this case,
the PLC sets the StatusBit RestartRequired". After restart of the axis, the PLC transfers the
changes to the working memory. The following table shows all axis parameters that are
connected to hardware configuration (Actor, Sensor, and PositionLimits) and required or
optional for simulation:
TODB parameter
Mode 1: Simulate PROFIdrive
Actor.Interface.AddressIn
Optional
Actor.Interface.AddressOut
Optional
Actor.Interface.EnableDriveOutput
Optional
Actor.Interface.DriveReadyInput
Optional
Sensor.Interface.AddressIn
Optional
Sensor.Interface.AddressOut
Optional
Sensor.ActiveHoming.DigitalInputAddress
Optional
Sensor.PassiveHoming.DigitalInputAddress
Optional
PositionLimits_HW.MinSwitchAddress
Optional
PositionLimits_HW.MaxSwitchAddress
Optional
S7-1200 Programmable controller
690
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.4.6
Data adaptation
Overview
You can adapt actor and sensor data that are readable from the drive or sensor module and
have been configured the same in both the PLC and the drive/sensor device.
Configuring Adaptation RT
The CPU configures the Adaptation RT in the TO-DB for the specific actor and sensor:
● .Sensor[i].DataAdaptation: DINT [ 0:NO | 1:YES ]
● .Actor.DataAdaptation: DINT [ 0:NO | 1:YES ]
You can change the Adaptation RT configuration during run with the axis configuration
dialog, Basic parameters, Drive and Encoder configuration dialogs. The adaptation is
effective with TO startup or restart or loss of communication to the drive.
In the TIA Portal, you select "Data adaptation" using the "Automatic acceptance of drive
values in the device" check box found in both of the axis configuration dialog, Basic
parameters, Drive and Encoder dialogs.
The following figure shows the axis configuration Drive dialog:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
691
Technology instructions
10.3 Motion control
● If a SINAMICS drive is connected:
– The check box is selected by default.
– The controls following the check box, "Reference speed’ and "Maximum speed", are
grayed out.
– Adaptation RT for actor data is activated.
– If you manually deselect the check box, you can change the values of both of the
controls following the check box.
● If no SINAMICS drive or another drive is connected:
– The check box is deselected and grayed out by default.
– The controls following the check box, "Reference speed’ and "Maximum speed", are
active and editable.
– Adaptation RT for actor data is not activated.
S7-1200 Programmable controller
692
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
The following figure shows the axis configuration Encoder dialog:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
693
Technology instructions
10.3 Motion control
● If a PROFIdrive encoder is connected:
– The check box is selected by default.
– The controls following the check box, "Encoder type" ("Steps per revolution" only) and
"Fine resolution", are grayed out.
– Adaptation RT for encoder data is activated.
– If you manually deselect the check box, you can change the values of both of the
controls following the check box.
● If no PROFIdrive encoder is connected (HSC or TM modules):
– The check box is deselected and grayed out by default.
– The controls following the check box, "Encoder type" and "Fine resolution", are active
and editable.
– Adaptation RT for actor data is not activated.
Executing Adaptation RT
You execute the adaptation with Adaptation RT activated:
● During startup of the Technology objects (TO) (or PLC startup) or creation of the TO (on
download of the TO-DB)
● After the drive or encoder blackout (or communication loss) and startup again
● Restart of TO (after every restart data are adapted)
During active communication of Adaptation RT, motion control refuses communication
orders from the user program regarding this drive and displays a resource error in the user
program.
A drop out of the drive breaks the adaptation during communication of Adaptation RT. If the
drive answers again, the adaptation starts again.
If the device makes a negative confirmation, motion control does not overwrite the TO axis
configuration. If Adaptation RT is selected, but the system does not operate an adaptation
successfully, motion control displays an error and the device cannot be enabled.
S7-1200 Programmable controller
694
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Displaying adaptation status and adaption errors
Motion control displays the Adaptation RT status and errors in parameters and
ErrorIDs/ErrorInfos:
● Motion control displays the adaptation status at the axis: If the adaptation does not
operate or operates with errors, motion control displays an error at the axis and the
ErrorID / ErrorInfo of the MC_Power instruction.
● General adaptation parameter: Manufacturer, device, version, and date are readout from
the P964[7] parameter. The P964 parameter is a PROFIdrive parameter and available at
the actor and encoder.
● Performance: Motion control executes the Adaptation RT after startup or restart. If the
configuration does not change afterwards, it is reasonable to deactivate the data
adaptation because of performance reasons. There are two solutions:
– Save the values by application in the RT after adaptation and deactivate the
adaptation.
– Upload of the values after adaptation, transfer these values to the project, and
deactivate the adaptation.
● Adaptation behavior:
– During startup / restart all configured devices (actor and sensor) to be adapted are
adapted.
– If a device is not adaptable during this step, motion control displays an error and the
status changes to "ADAPTATION_ERROR".
– With errors of an encoder, an enabling of the axis in the speed controlled mode is
possible because this mode usually works without an encoder.
Refer to "ErrorIDs and ErrorInfos for motion control" for a listing of the data adaptation
ErrorIDs and ErrorInfos.
Adapting actor data
The adaptation of actor data is device specific and supported only for SINAMICS drives.
SINAMICS drives support data adaptation and show an error if Adaptation RT is activated.
Units
Adaptation of actor data considers the configured units in the drive. Values and units depend
on the DO-Type, DO-Function module, and units system.
Adaptation of actor data only supports rotary drives (no linear drives) and units of 1/min.
The following parameters are read and evaluated:
● p107 (DO-Typ)
● p108 (DO-Function module)
● p505 (SI units or US units)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
695
Technology instructions
10.3 Motion control
Selected current data record from the drive
A SINAMICS drive supports different data sets for the encoder and actor. The SINAMICS
drive adapts the current data record at the moment of adaptation. Therefore, "p51" (current
data record of drive) is readout:
● The reference speed is equal to all data records: "p2000" (reference speed) is
independent of the data record.
● The maximum speed is independent of the data record: "p1082"
● The SINAMICS drive does not check the different maximum values of the different data
records if they are consistent regarding their control value in the current data record. For
example, this happens after a data adaptation to another data record.
Motor type
SINAMICS supports two motor types:
● Linear motor
● Default motor (rotary motor)
With Basic Motion Control (BMC), SINAMICS only supports rotary motors.
If the SINAMICS drive has a linear motor configured (parameter "r108, bit 12"), motion
control displays an ErrorID after a consistency check or a data adaptation abort.
Parameters
Motion control supports "DO-Servo" and "DO-Vector". The following parameters of the drive
are adapted:
TO-DB actor parameter
SINAMICS parameter
Actor.DriveParameter.ReferenceSpeed
p2000
Actor.DriveParameter.MaxSpeed
p1082
Three TO DB parameters of the actor are not adapted but checked on plausibility:
TO-DB sensor parameter
SINAMICS/PROFIdrive parameter
Actor.type
r108, bit12
Actor.Interface.AddressIn.RID
p922 or p2079
Actor.Interface.AddressOut.RID
p922 or p2079
S7-1200 Programmable controller
696
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
The values of each parameter are listed in the following tables:
TO-DB actor parameter
Value
Actor.type
•
0 = Analog
•
1 = PROFIdrive
• 2 = PTO
Note: The TIA Portal only supports the rotary
drive. This means that only a "1" value is valid.
Actor.Interface.AddressIn.RID
Actor.Interface.AddressOut.RID
•
0208_0708 = Telegram 1
•
0208_070A = Telegram 2
•
0208_070C = Telegram 3
•
0208_0720 = Telegram 4
•
0208_070E = Telegram 81
•
0208_0710 = Telegram 83
•
0208_0709 = Telegram 1
•
0208_070B = Telegram 2
•
0208_070D = Telegram 3
•
0208_0721 = Telegram 4
•
0208_070F = Telegram 81
•
0208_0711 = Telegram 83
SINAMICS/PROFIdrive parameter
Value
r108, bit12
•
0 = Linear drive
• 1 = Rotary drive
Note: The TIA Portal only supports the rotary
drive.
p922 or p2079
•
1 = Telegram 1
•
2 = Telegram 2
•
3 = Telegram 3
•
4 = Telegram 4
•
81 = Telegram 81
•
83 = Telegram 83
Check of the maximum velocity
The TIA Portal verifies the validity of the TO-DB "DynamicLimits.MaxVelocity" parameter.
However, with data adaptation, the check is only possible when the system is in RUN and
does not perform the TIA Portal verification.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
697
Technology instructions
10.3 Motion control
Consistency check
Motion control executes a consistency check during the first startup or restart of the TO axis.
Motion control also displays an ErrorID if the data adaptation of the actor is activated. A
consistency check involves the telegram, motor type, and maximum speed:
● Telegram in "p922" or "p2079": If there is an inconsistency between the TO and drive
configuration, motion control displays an error.
● Motor type in "r108, bit12" of DO-Servo: If there is an inconsistency between the TO and
drive configuration, motion control displays an error.
● The maximum speed is not reachable with the configured axis parameters, and motion
control displays an error. (Note: Motion control does not display this error again after
confirmation if the axis configuration is not changed.)
Special case:
● Maximum speed (p1082) > 2 x reference speed (p2000)
● Motion control reduces the maximum speed to "2x" reference speed internally. The entry
in the axis configuration is not limited. However, motion control adapts the value of
"p1082" and displays an error.
Adapting sensor data
Only data adaptation with an active encoder is supported (p0979).
Amount of adapted data
Motion control adapts the actual value description of "p0979" (including the rotary or linear
encoder configuration) and checks the TIA Portal encoder type parameter, "incremental or
absolute". Motion control does not adapt or evaluate the NIST reference value in Telegram
83.
Correlating the encoder in the telegram to the encoder in the PLC and drive
● Motion control configures the mapping of an encoder in the PLC to the actual value in the
telegram (actual value 1 or actual value 2) in the VREF.RID of two TO-DB parameters:
– .Sensor[i].Interface.AddressIn
– .Sensor[i].Interface.AddressOut
● The mapping in the drive occurs with the index setting in "p979" (encoder modeling in
SINAMICS).
S7-1200 Programmable controller
698
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Parameters
Motion control adapts the following prarmeters:
TO-DB sensor parameter
SINAMICS/PROFIdrive parameter
Sensor[i].System
•
P979.[1] or P979.[11]
•
Bit 0 = 0: rotary encoder
•
Bit 0 = 1: linear encoder
Incremental rotary sensor
Sensor[i].Parameter.StepsPerRevolution
P979.[2] or P979.[12]
Sensor[i].Parameter.FineResolutionXist1
P979.[3] or P979.[13]
Incremental linear sensor
Sensor[i].Parameter.Resolution
P979.[2] or P979.[12]
Sensor[i].Parameter.FineResolutionXist1
P979.[3] or P979.[13]
Absolute rotary sensor
Sensor[i].Parameter.StepsPerRevolution
P979.[2] or P979.[12]
Sensor[i].Parameter.FineResolutionXist1
P979.[3] or P979.[13]
Sensor[i].Parameter.DeterminableRevolutions
P979.[5] or P979.[15]
Sensor[i].Parameter.FineResolutionXist2
P979.[4], bzw.P979.[14]
Absolute linear sensor
Sensor[i].Parameter.Resolution
P979.[2] or P979.[12]
Sensor[i].Parameter.FineResolutionXist1
P979.[3] or P979.[13]
Sensor[i].Parameter.FineResolutionXist2
P979.[4], bzw. P979.[14]
Motion control does not adapt one TO-DB sensor parameter, but checks it on consistency:
TO-DB sensor parameter
SINAMICS/PROFIdrive parameter
Sensor[i].Type
•
P979.[5], bzw. P979.[15]
•
Bit 0 = 0: incremental encoder
•
Bit 0 > 1: absolute encoder
Sensor[i].Interface.AddressIn
p922 or p2079
Sensor[i].Interface.AddressOut
You can use an absolute encoder as an incremental encoder, but not an incremental
encoder as an absolute encoder. Motion control displays an incompatibility of the encoder
type at the TO and its related actual value in the PROFIdrive telegram in an error. Note: With
SINAMICS FW V2.6, the PROFIdrive interface has a sensor zero mark.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
699
Technology instructions
10.3 Motion control
Consistency check
Motion control executes a consistency check during the first startup or restart of the TO axis.
Motion control also displays an ErrorID if the data adaptation of the sensor is activated. A
consistency check involves the telegram and sensor type:
● Telegram in "p922" or "p2079": If there is an inconsistency between the TO and sensor
configuration, motion control displays an error.
● Sensor type in "P979.[5]" or "P979.[15]": You can use an absolute encoder as an
incremental encoder, but not an incremental encoder as an absolute encoder. If there is
no consistency, motion control displays an error.
Parameters that must be uploaded
The following list shows all the parameters that you have to upload from the drive into the
TIA portal. To manage this data adaptation, you must expand the TO-DB. You use the
following structs of the TO-DB to perform this expansion:
Actor
Type
AcDINT
tor.DataAdaptation
Default
Changeable
Comment
0
R (with restart)
Adaptation activate:
StatusDrive
Type
Comment
StatusDrive.AdaptationState
DINT
Adaptation status:
•
0: NO
•
1: YES
•
0: NOT_ADAPTED: Cannot take
over data.
•
1: IN_ADAPTATION: Data adaptation has just started.
•
2: ADAPTED: Data are adapted
•
3:NOT_APPLICABLE: Adaptation
not selected or not available for this
drive
•
4:ADAPTATION_ERROR: Error
during adaptation:
–
Axis cannot be enabled.
–
Motion control displays a configuration error.
S7-1200 Programmable controller
700
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Sensor
Type
Default
Changeable
Comment
Sensor.DataAdaptation
DINT
0
R (with restart)
Adaptation activate:
StatusSensor
Type
Comment
StatusSensor.AdaptationState
DINT
Adaptation status:
ErrorWord
Type
...
Bool
Bit 15: Adaptation Error
Bool
...
Bool
•
0: NO
•
1: YES
•
0: NOT_ADAPTED: Cannot take
over data.
•
1: IN_ADAPTATION: Data adaptation has just started.
•
2: ADAPTED: Data are adapted.
•
3: NOT_APPLICABLE: Adaptation
not selected or not available for this
drive.
•
4: ADAPTATION_ERROR: Error
during adaptation:
–
Axis cannot be enabled.
–
Motion control displays a configuration error.
Comment
ErrorID:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
701
Technology instructions
10.3 Motion control
10.3.4.7
Axis control using the TM Pulse module
The TM Pulse Module is an ET 200SP two-channel pulse output module for use with valves
and motors. The module can support either two 24 V DC channels at 2 A or one 24 V DC
channel at 4 A.
Using the "DC motor" operating mode of the TM Pulse 2x24V output module, you can drive a
motor in both directions with a bipolar PWM output. You can assign a digital input as an
"External stop" signal for the motor.
The TM Pulse module can perform the following functions to support motion control:
● Programmable output response to CPU/master STOP condition
● Error detection and diagnostics:
– Missing or under voltage L+ supply voltage
– Short-circuit/overload of a digital output
– Short-circuit/under voltage of a sensor power supply
– Over temperature error
– Parameterization fault
– Module/firmware error
Example
Some applications require the ability to move easily to a specific location, but do not require
the absolute accuracy and adherence to a specific profile. The use of a common DC motor in
conjunction with the Closed Loop Servo control is possible using the ET 200SP TM Pulse
module to control the motor. This application example covers one mode of the ET 200SP TM
Pulse module: "PWM with DC Motor". Refer to the ET 200SP Technology module TM Pulse
2x24V Manual for further information on the other ET 200SP TM Pulse modes.
In order to use true closed loop control, you require a method of position feedback. You must
connect an encoder to the motor to provide feedback to the control system. This example
shows three methods of achieving this:
● High Speed Counter (HSC) that is built into the S7-1200
● ET 200SP TM Count Module
● ET 200SP TM Position module
In some cases, where moving at various velocities is a requirement, the Closed Loop control
can operate in Speed Control mode. If you use this mode, you do not require position
feedback.
S7-1200 Programmable controller
702
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Follow these steps to configure the TM Pulse module:
1. Configure your S7-1200 CPU.
2. Select the required ET 200SP Interface module and place it in the Device View:
3. Add the ET 200SP TM Pulse module:
4. In the Channel configuration, select "2 channels (2A)".
5. Set the Operating mode to "PWM with DC Motor".
6. Set the Diagnostics and Channel parameters as required.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
703
Technology instructions
10.3 Motion control
Follow these steps to configure the Axis of Motion with position feedback:
1. When configuring your interface with a Closed Loop Motion Control System, you use
analog control, not PROFIdrive or PTO. You configure the axis to be controlled in the
same way that you configure an axis that uses an analog output as the input to a servo
drive. Add a "TO PositioningAxis" as shown in the figure below:
S7-1200 Programmable controller
704
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
2. In the General configuration dialog for the axis configuration, select "Analog drive
connection":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
705
Technology instructions
10.3 Motion control
3. You now need analog outputs and a drive enable for your drive configuration. Go to the
Device View of the ET 200SP interface module and the Device Overview entry for the TM
Pulse module. Using the starting Q address for the TM Pulse module and the Control
interface and Feedback interface tables in the SIMATIC ET 200SP Technology module
TM Pulse 2x24V (6ES7138-6DB00-0BB1) Manual, you can determine the following
analog outputs and drive enable required for your drive:
– Analog output
– Select enable output
– Select ready input
In the Drive configuration dialog for the axis configuration, select your hardware interface
I/O and data exchange values:
S7-1200 Programmable controller
706
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
4. In the Encoder configuration dialog for the axis configuration, complete the configuration
by selecting one of the following encoders:
● TM Count module
● TM Pulse module
● High-Speed Counter (HSC)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
707
Technology instructions
10.3 Motion control
10.3.5
Configuring the TO_CommandTable_PTO
You can configure a MC_CommandTable instruction using the Technology objects. The
following example demonstrates how this is done.
Adding a Technology object
1. In the Project tree, expand the node "Technology Objects" and select "Add new object".
2. Select the "CommandTable" icon (rename if required), and click "OK" to open the
configuration editor for the CommandTable object.
S7-1200 Programmable controller
708
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Planning the steps for your application
You can create the desired movement sequence in the "Command Table" configuration
window, and check the result against the graphic view in the trend diagram.
You can select the command types that are to be used for processing the command table.
Up to 32 steps can be entered. The commands are processed in sequence, easily producing
a complex motion profile.
Table 10- 48 MC_CommandTable command types
Command type
Description
Empty
The empty serves as a placeholder for any commands to be added. The
empty entry is ignored when the command table is processed
Halt
Pause axis.
Note: The command only takes place after a "Velocity setpoint" command.
Positioning Relative
Positions the axis based upon distance. The command moves the axis by
the given distance and velocity.
Positioning Absolute
Positions the axis based upon location. The command moves the axis to
the given location, using the velocity specified.
Velocity setpoint
Moves the axis at the given velocity.
Wait
Waits until the given period is over. "Wait" does not stop an active traversing motion.
Separator
Adds a "Separator" line above the selected line. The separator line allows
more than one profile to be defined in a single command table.
In the figure below, "Command complete" is used as the transition to the next step. This type
of transition allows your device to decelerate to the start/stop speed and then accelerate
once again at the start of the next step.
① Axis decelerates to the start/stop speed between steps.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
709
Technology instructions
10.3 Motion control
In the figure below, "Blending motion" is used as the transition to the next step. This type of
transition allows your device to maintain its velocity into the start of the next step, resulting in
a smooth transition for the device from one step to the next. Using blending can shorten the
total time required for a profile to execute completely. Without blending, this example takes
seven seconds to run. With blending, the execution time is reduced by one second to a total
of six seconds.
① Axis continues to move and accelerates or decelerates to the next step velocity, saving time and
mechanical wear.
The operation of your CommandTable is controlled by an MC_CommandTable instruction,
as shown below:
S7-1200 Programmable controller
710
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.6
Operation of motion control for S7-1200
10.3.6.1
CPU outputs used for motion control
The CPU provides four pulse output generators. Each pulse output generator provides one
pulse output and one direction output for controlling a stepper motor drive or a servo motor
drive with pulse interface. The pulse output provides the drive with the pulses required for
motor motion. The direction output controls the travel direction of the drive.
The PTO output generates a square wave output of variable frequency. Pulse generation is
controlled by configuration and execution information supplied through H/W configuration
and/or SFCs/SFBs.
Based upon the user’s selection while the CPU is in RUN mode, either the values stored in
the image register or the pulse generator outputs drive the digital outputs. In STOP mode,
the PTO generator does not control the outputs.
Onboard CPU outputs and outputs of a signal board can be used as pulse and direction
outputs. You select between onboard CPU outputs and outputs of the signal board during
device configuration under Pulse generators (PTO/PWM) on the "Properties" tab. Only PTO
(Pulse Train Output) applies to motion control.
The table below shows the default I/O assignments; however, the four pulse generators can
be configured to any digital output.
Note
Pulse-train outputs cannot be used by other instructions in the user program.
When you configure the outputs of the CPU or signal board as pulse generators (for use with
the PWM or motion control instructions), the corresponding output addresses no longer
control the outputs. If your user program writes a value to an output used as a pulse
generator, the CPU does not write that value to the physical output.
Note
PTO direction outputs can be freed for use elsewhere in your program.
Each PTO requires the assignment of two outputs: one as a pulse output and one as a
direction output. You can use just the pulse output and not the direction output. You can then
free the direction output for other purposes in your user program. The output cannot be used
for both the PTO direction output and in the user program, simultaneously.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
711
Technology instructions
10.3 Motion control
Table 10- 49 Default address assignments of the pulse and direction outputs
Usage of outputs for motion control
Pulse
Direction
Built-in I/O
Q0.0
Q0.1
SB I/O
Q4.0
Q4.1
PTO1
PTO2
Built-in I/O
Q0.2
Q0.3
SB I/O
Q4.2 1
Q4.3 1
Built-in I/O
Q0.4 2
Q0.5 2
SB I/O
Q4.0
Q4.1
Built-in I/O
Q0.6 3
Q0.7 3
SB I/O
Q4.2
Q4.3
PTO3
PTO4
1
Outputs Q4.2 and Q4.3 are only available on the SB 1222 DQ4.
2
The CPU 1211C does not have outputs Q0.4, Q0.5, Q0.6, or Q0.7. Therefore, these outputs cannot be used in the CPU 1211C.
3
The CPU 1212C does not have outputs Q0.6 or Q0.7. Therefore, these outputs cannot be used in
the CPU 1212C.
4
This table applies to the CPU 1211C, CPU 1212C, CPU 1214C, CPU 1215C, and CPU 1217C
PTO functions.
Drive interface
For motion control, you can optionally configure a drive interface for "Drive enabled" and
"Drive ready". When using the drive interface, the digital output for the drive enable and the
digital input for "drive ready" can be freely selected.
Note
The firmware will take control through the corresponding pulse and direction outputs if the
PTO (Pulse Train Output) has been selected and assigned to an axis.
With this takeover of the control function, the connection between the process image and I/O
output is also disconnected. While the user has the possibility of writing the process image of
pulse and direction outputs via the user program or watch table, this is never transferred to
the I/O output. Accordingly, it is also not possible to monitor the I/O output via the user
program or watch table. The information read merely reflects the value of the process image
and does not match the actual status of the I/O output in any respect.
For all other CPU outputs that are not used permanently by the CPU firmware, the status of
the I/O output can be controlled or monitored via the process image, as usual.
S7-1200 Programmable controller
712
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.6.2
Hardware and software limit switches for motion control
Use the hardware and software limit switches to limit the "allowed travel range" and the
"working range" of your axis.
①
②
③
Mechanical stop
A
Allowed travel range for the axis
Lower and upper hardware limits
B
Working range of the axis
Lower and upper software limits
C
Distance
Hardware and software limit switches must be activated prior to use in the configuration or in
the user program. Software limit switches are only active after homing the axis.
Hardware limit switches
Hardware limit switches determine the maximum travel range of the axis. Hardware limit
switches are physical switching elements that must be connected to interrupt-capable inputs
of the CPU. Use only hardware limit switches that remain permanently switched after being
approached. This switching status can only be revoked after a return to the allowed travel
range.
Table 10- 50 Available inputs for hardware limits
Description
CPU
RPS, LIM-, and LIM+ 1
Built-in I/O
CPU 1211C
I0.0 - I0.5
CPU 1212C
I0.0 - I0.7
CPU 1214C, CPU 1215C, and
CPU 1217C
I0.0 - I01.3
All S7-1200 CPUs
I4.0 - I4.3
SB I/O
1
Reference Point Switch input (RPS), Negative Travel Limit input (LIM-), and Positive Travel Limit
input (LIM+)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
713
Technology instructions
10.3 Motion control
When the hardware limit switches are approached, the axis brakes to a standstill at the
configured emergency deceleration. The specified emergency deceleration must be
sufficient to reliably stop the axis before the mechanical stop. The following diagram
presents the behavior of the axis after it approaches the hardware limit switches.
①
②
The axis brakes to a standstill at the configured emergency deceleration.
A
[Velocity]
B
Allowed travel range
C
Distance
D
Mechanical stop
E
Lower hardware limit switch
F
Upper hardware limit switch
Range in which the hardware limit switches signal the stats "approached".
WARNING
Risks with changes to filter time for digital input channel
If the filter time for a digital input channel is changed from a previous setting, a new "0"
level input value needs to be presented for up to 20.0 ms accumulated duration before the
filter becomes fully responsive to new inputs. During this time, short "0" pulse events of
duration less than 20.0 ms cannot be detected or counted.
This changing of filter times can result in unexpected machine or process operation, which
can cause death or serious injury to personnel, and/or damage to equipment.
To ensure that a new filter time goes immediately into effect, a power cycle of the CPU
must be applied.
S7-1200 Programmable controller
714
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Software limit switches
Software limit switches limit the "working range" of the axis. They must fall inside the
hardware limit switches relative to the travel range. Because the positions of the software
limit switches can be set flexibly, the working range of the axis can be restricted on an
individual basis depending on the current traversing profile. In contrast to hardware limit
switches, software limit switches are implemented exclusively by means of the software and
do not require their own switching elements.
If software limit switches are activated, an active motion is stopped at the position of the
software limit switch. The axis is braked at the configured deceleration. The following
diagram presents the behavior of the axis until it reaches the software limit switches.
①
The axis brakes to a standstill at the configured deceleration.
A
[Velocity]
B
Working range
C
Distance
D
Lower software limit switch
E
Upper software limit switch
Use additional hardware limit switches if a mechanical endstop is located after the software
limit switches and there is a risk of mechanical damage.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
715
Technology instructions
10.3 Motion control
Edge detection configuration on address change
If you configure a position limit or input homing switch to an input address in a TO
PositionAxis, motion control configures it with edge interrupts automatically. If, then, you
change the position limit or input homing switch to another address, the configuration with
edge detection for the old address remains active.
In the axis configuration, Extended parameters, Position limits dialog, you can add hardware
and software limit switches. When you add a hardware limit switch input, an edge detection
is automatically activated. Later, if you decide to change an input address, an edge detection
dialog displays which offers the following choices:
● Yes: Changes to the new address, activates edge detection on the new address, and
deactivates edge detection on the old address (default selection)
● No: Changes to the new address, activates edge detection on the new address, and
maintains edge detection on the old address
● Cancel: Does not change to a new address and maintains current edge detection state
Edge detection dialog
selection
Changes to new address
Activates edge dectection on new address
Deactivates edge detection on old address
Yes (default)
Yes
Yes
Yes
No
Yes
Yes
No
Cancel
No
N/A
No
Note
For Servo configurations that require no edge detection, no dialog displays.
Note
If an OB is linked to the input, motion control does not perform operations with edge
detection as described above.
S7-1200 Programmable controller
716
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: Changing to a new HW limit switch address with edge detection and deactivating edge
detection on the old address
1. Current state: You have connected an "Input low HW limit switch" to I0.2. This
configuration automatically enabled edge detection on I0.2. This configuration is also
shown in the CPU Properties, Digital Inputs:
2. You change "Input low HW limit switch" to I0.6 and confirm. The edge detection dialog
displays. You select: "Yes: Change address and deactivate edge detection on old
address.":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
717
Technology instructions
10.3 Motion control
3. The CPU accepts the new I0.6 address and activates edge detection on the I0.6. The
edge detection of I0.2 in the CPU Properties, Digital Inputs is automatically deactivated:
S7-1200 Programmable controller
718
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: Changing to a new HW limit switch address with edge detection and maintaining edge
detection on the old address
1. Current state: You have connected an "Input low HW limit switch" to I0.2. This
configuration automatically enabled edge detection on I0.2. This configuration is also
shown in the CPU Properties, Digital Inputs:
2. You change "Input low HW limit switch" to I0.6 and confirm. The edge detection dialog
displays. You select: "No: Change address and keep edge detection on old address.":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
719
Technology instructions
10.3 Motion control
3. The CPU accepts the new I0.6 address and activates edge detection on the I0.6. The
edge detection of I0.2 in the CPU Properties, Digital Inputs is kept activated:
S7-1200 Programmable controller
720
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: Canceling change to a new HW limit switch address with edge detection
1. Current state: You have connected an "Input low HW limit switch" to I0.2. This
configuration automatically enabled edge detection on I0.2. This configuration is also
shown in the CPU Properties, Digital Inputs:
2. You change "Input low HW limit switch" to I0.6 and confirm. The edge detection dialog
displays. You select: "Cancel.":
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
721
Technology instructions
10.3 Motion control
3. The "Input low HW limit switch" remains configured to I0.2 and edge detection on I0.2
remains activated:
Additional information
Your user program can override the hardware or software position limits by enabling or
disabling both hardware and software limits functionality. The selection is made from the
Axis DB.
● To enable or disable the hardware limit functionality, access the "Active" tag (Bool) in the
DB path "/Config/PositonLimits_HW". The state of the "Active" tag enables
or disables the use of hardware position limits.
● To enable or disable software position limit functionality, access "Active" tag (Bool) in the
DB path "/Config/Position Limits_SW". The state of this "Active" tag enables
or disables the software position limits.
You can also modify the software position limits with your user program (for example, to add
flexibility for machine setup or to shorten machine change-over time). Your user program can
write new values to the " MinPosition " and " MaxPosition " tags (engineering units in Real
format) in the DB "/Config/PositionLimits_SW".
S7-1200 Programmable controller
722
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.6.3
Homing
Homing refers to the matching of the axis coordinates to the real, physical drive position. (If
the drive is currently at position x, the axis will be adjusted to be in position x.) For positioncontrolled axes, the entries and displays for the position refer exactly to these axis
coordinates.
Note
The agreement between the axis coordinates and the real situation is extremely important.
This step is necessary to ensure that the absolute target position of the axis is also achieved
exactly with the drive.
The MC_Home instruction initiates the homing of the axis.
There are 4 different homing functions. The first two functions allow the user to set the
current position of the axis and the second two position the axis with respect to a Home
reference Sensor.
● Mode 0 - Direct Referencing Absolute: When executed this mode tells the axis exactly
where it is. It sets the internal position variable to the value of the Position input of the
Homing instruction. This is used for machine calibration and setup.
The axis position is set regardless of the reference point switch. Active traversing motions
are not aborted. The value of the Position input parameter of the MC_Home instruction is
set immediately as the reference point of the axis. To assign the reference point to an
exact mechanical position, the axis must be at a standstill at this position at the time of
the homing operation.
● Mode 1 - Direct Referencing Relative: When executed this mode uses the internal
position variable and adds the value of the Position input on the Homing instruction to it.
This is typically used to account for machine offset.
The axis position is set regardless of the reference point switch. Active traversing motions
are not aborted. The following statement applies to the axis position after homing: New
axis position = current axis position + value of the Position parameter of the MC_Home
instruction.
● Mode 2 - Passive Referencing: When the axis is moving and passes the Reference Point
Switch the current position is set as the home position. This feature will help account for
normal machine wear and gear backlash and prevent the need for manual compensation
for wear. The Position input on the Homing instruction, as before, adds to the location
indicated by the Reference Point Switch allowing easy offset of the Home position.
During passive homing, the MC_Home instruction does not carry out any homing motion.
The traversing motion required for this step must be implemented by the user via other
motion control instructions. When the reference point switch is detected, the axis is
homed according to the configuration. Active traversing motions are not aborted upon
start of passive homing.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
723
Technology instructions
10.3 Motion control
● Mode 3 - Active Referencing: This mode is the most precise method of Homing the Axis.
The initial direction and velocity of movement is configured in the Technology Object
Configuration Extended Parameters-Homing. This is dependent upon machine
configuration. There is also the ability to determine if the leading edge or falling edge of
the Reference Point Switch signal is the Home position. Virtually all sensors have an
active range and if the Steady State On position was used as the Home signal then there
would be a possibility for error in the Homing position since the On signal active range
would cover a range of distance. By using either the leading or falling edge of that signal
a much more precise Home position results. As with all other modes the value of the
Position input on the Homing instruction is added to the Hardware referenced position.
In active homing mode, the MC_Home instruction performs the required reference point
approach. When the reference point switch is detected, the axis is homed according to
the configuration. Active traversing motions are aborted.
Modes 0 and 1 do not require that the axis be moved at all. They are typically used in setup
and calibration. Modes 2 and 3 require that the axis move and pass a sensor that is
configured in the "Axis" technology object as the Reference Point Switch. The reference
point can be placed in the work area of the axis or outside of the normal work area but within
movement range.
Configuration of homing parameters
You configure the parameters for active and passive homing in the "Homing" configuration
window. The homing method is set using the "Mode" input parameter of the motion control
instruction. Here, Mode = 2 means passive homing and Mode = 3 means active homing.
Note
Use one of the following measures to ensure that the machine does not travel to a
mechanical endstop in the event of a direction reversal:
• Keep the approach velocity low
• Increase the configured acceleration/deceleration
• Increase the distance between hardware limit switch and mechanical stop
S7-1200 Programmable controller
724
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 51 Configuration parameters for homing the axis
Parameter
Description
Input reference point switch
Select the digital input for the reference point switch from the drop-down list box. The
input must be interrupt-capable. The onboard CPU inputs and inputs of an inserted
signal board can be selected as inputs for the reference point switch.
(Active and passive homing)
The default filter time for the digital inputs is 6.4 ms. When the digital inputs are used
as a reference point switch, this can result in undesired decelerations and thus inaccuracies. Depending on the homing velocity and extent of the reference point switch,
the reference point may not be detected. The filter time can be set under "Input filter"
in the device configuration of the digital inputs.
The specified filter time must be less than the duration of the input signal at the reference point switch.
Reference point switch
•
Active homing: Select whether the axis is to be referenced on the bottom or top
side of the reference point switch. Depending on the start position of the axis and
the configuration of the homing parameters, the reference point approach sequence can differ from the diagram in the configuration window.
•
Passive homing: With passive homing, the traversing motions for purposes of
homing must be implemented by the user via motion commands. The side of the
reference point switch on which homing occurs depends on the following factors:
(Active and passive homing)
Auto reverse after reaching the
hardware limit switches
(Active homing only)
–
"Reference point switch" configuration
–
Current travel direction during passive homing
Activate the check box to use the hardware limit switch as a reversing cam for the
reference point approach. The hardware limit switches must be configured and activated for direction reversal.
If the hardware limit switch is reached during active homing, the axis brakes at the
configured deceleration (not with the emergency deceleration) and reverses direction.
The reference point switch is then sensed in reverse direction.
If the direction reversal is not active and the axis reaches the hardware limit switch
during active homing, the reference point approach is aborted with an error and the
axis is braked at the emergency deceleration.
Approach direction
(Active and passive homing)
Approach velocity
(Active homing only)
With the direction selection, you determine the "approach direction" used during active homing to search for the reference point switch, as well as the homing direction.
The homing direction specifies the travel direction the axis uses to approach the
configured side of the reference point switch to carry out the homing operation.
Specify the velocity at which the reference point switch is to be searched for during
the reference point approach.
Limit values (independent of the selected user unit):
Start/stop velocity ≤ approach velocity ≤ maximum velocity
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
725
Technology instructions
10.3 Motion control
Parameter
Description
Homing velocity
Specify the velocity at which the axis approaches the reference point switch for homing.
(Active homing only)
Limit values (independent of the selected user unit):
Start/stop velocity ≤ homing velocity ≤ maximum velocity
Home position offset
(Active homing only)
If the desired reference position deviates from the position of the reference point
switch, the home position offset can be specified in this field.
If the value does not equal 0, the axis executes the following actions following homing
at the reference point switch:
1. Move the axis at homing velocity by the value of the home position offset.
2. When the position of the home position offset is reached, the axis position is set
to the absolute reference position. The absolute reference position is specified via
parameter "Position" of motion control instruction "MC_Home".
Limit values (independent of the selected user unit):
-1.0e12 ≤ home position offset ≤ 1.0e12
Table 10- 52 Factors that affect homing
Influencing factors:
Configuration
Configuration
Approach direction
Reference point switch
Positive
"Bottom (negative) side"
Positive
"Top (positive) side"
Negative
"Bottom (negative) side"
Negative
"Top (positive) side"
Result:
Current travel direction
Homing on
Reference point switch
Positive direction
Bottom
Negative direction
Top
Positive direction
Top
Negative direction
Bottom
Positive direction
Top
Negative direction
Bottom
Positive direction
Bottom
Negative direction
Top
Homing reference point switch level
In the axis configuration Homing dialog, Passive or Active, you configure your "Digital input
homing switch". As part of this configuration, you can also change the levels (high or low) of
the closed loop axes (PROFIdrive and analog) reference point switches. The default value is
high level.
S7-1200 Programmable controller
726
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Example: Selecting the passive reference point switch level
1. You have configured an S7-1200 project with an Analog/PROFIdrive axis using passive
homing. Depending on your application, you select "High level" or "Low level" for the
passive homing switch level:
2. The program executes a passive homing.
3. After finishing the passive homing, the axis is homed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
727
Technology instructions
10.3 Motion control
Example: Selecting the active reference point switch level
1. You have configured an S7-1200 project with an Analog/PROFIdrive axis using active
homing. Depending on your application, you select "High level" or "Low level" for the
active homing switch level:
2. The program executes an active homing.
3. After finishing the active homing, the axis is homed.
S7-1200 Programmable controller
728
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Sequence for active homing
You start active homing with motion control instruction "MC_Home" (input parameter
Mode = 3). Input parameter "Position" specifies the absolute reference point coordinates in
this case. Alternatively, you can start active homing on the control panel for test purposes.
The following diagram shows an example of a characteristic curve for an active reference
point approach with the following configuration parameters:
● "Approach direction" = "Positive approach direction"
● "Reference point switch" = "Top (positive) side"
● Value of "home position offset" > 0
Table 10- 53 Velocity characteristics of MC homing
Operation
Notes
A
Approach velocity
B
Homing velocity
C
Home position coordinate
D
Home position offset
①
Search phase (blue curve segment): When active homing starts, the axis accelerates to the configured "approach
velocity" and searches at this velocity for the reference point switch.
②
Reference point approach (red curve section): When the reference point switch is detected, the axis in this example
brakes and reverses, to be homed on the configured side of the reference point switch at the configured "homing
velocity".
③
Travel to reference point position (green curve segment): After homing at the reference point switch, the axis travels
to the "Reference point coordinates" at the "homing velocity". On reaching the "Reference point coordinates", the
axis is stopped at the position value that was specified in the Position input parameter of the MC_Home instruction".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
729
Technology instructions
10.3 Motion control
Note
If the homing search does not function as you expected, check the inputs assigned to the
hardware limits or to the reference point. These inputs may have had their edge interrupts
disabled in device configuration.
Examine the configuration data for the axis technology object of concern to see which inputs
(if any) are assigned for "HW Low Limit Switch Input", "HW High Limit Switch Input", and
"Input reference point switch". Then open the Device configuration for the CPU and examine
each of the assigned inputs. Verify the "Enable rising edge detection" and "Enable falling
edge detection" are both selected. If these properties are not selected, delete the specified
inputs in the axis configuration and select them again.
10.3.6.4
Jerk limit
With the jerk limit you can reduce the stresses on your mechanics during an acceleration
and deceleration ramp. The value for the acceleration and deceleration is not changed
abruptly when the step limiter is active; it is adapted in a transition phase. The figure below
shows the velocity and acceleration curve without and with jerk limit.
Table 10- 54 Jerk limit
Travel without step limiter
Travel with step limiter
The jerk limit gives a "smoothed" velocity profile of the axis motion. This ensures soft starting
and braking of a conveyor belt for example.
S7-1200 Programmable controller
730
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.7
Motion control instructions
10.3.7.1
MC instruction overview
The motion control instructions use an associated technology data block and the dedicated
PTO (pulse train outputs) of the CPU to control the motion on an axis.
● MC_Power (Page 733) enables and disables a motion control axis.
● MC_Reset (Page 736) resets all motion control errors. All motion control errors that can
be acknowledged are acknowledged.
● MC_Home (Page 737) establishes the relationship between the axis control program and
the axis mechanical positioning system.
● MC_Halt (Page 740) cancels all motion processes and causes the axis motion to stop.
The stop position is not defined.
● MC_MoveAbsolute (Page 742) starts motion to an absolute position. The job ends when
the target position is reached.
● MC_MoveRelative (Page 745) starts a positioning motion relative to the start position.
● MC_MoveVelocity (Page 747) causes the axis to travel with the specified speed.
● MC_MoveJog (Page 749) executes jog mode for testing and startup purposes.
● MC_CommandTable (Page 751) runs axis commands as a movement sequence.
● MC_ChangeDynamic (Page 754) changes Dynamics settings for the axis.
● MC_WriteParam (Page 756) writes a select number of parameters to change the
functionality of the axis from the user program.
● MC_ReadParam (Page 758) reads a select number of parameters that indicate the
current position, velocity, and so forth of the axis defined in the Axis input.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
731
Technology instructions
10.3 Motion control
CPU firmware levels
If you have an S7-1200 CPU with V4.1 or later firmware, select the V5.0 version of each
motion instruction.
If you have an S7-1200 CPU with V4.0 or earlier firmware, select the applicable V4.0, V3.0,
V2.0, or V1.0 version of each motion instruction.
Note
Instructions in motion control V1.0 to V3.0 actively control the ENO output of the instruction.
When an error occurs within the block, the ENO output is turned to the OFF state. An error is
indicated by the ERROR, ErrorID, and ErrorInfo outputs on the block. Using the ENO output,
it is possible to evaluate the status of the instruction and execute subsequent instructions
after it in a serial manner.
With instructions in motion control V4.0 and V5.0, the ENO output stays true as long as the
instruction executes regardless of its error state. This could cause a program that used V3.0
or earlier motion control that depends on the ENO status to function incorrectly. To remedy
this situation, use the DONE and ERROR outputs to evaluate the status of the instruction
rather than the ENO output when using motion control V4.0 or later.
Note
The CPU calculates motion tasks in "slices" or segments of 10 ms. As one slice is being
executed, the next slice is waiting in the queue to be executed. If you interrupt the motion
task on an axis (by executing another new motion task for that axis), the new motion task
cannot be executed for a maximum of 20 ms (the remainder of the current slice plus the
queued slice).
S7-1200 Programmable controller
732
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.7.2
MC_Power (Release/block axis)
Note
If the axis is switched off due to an error, it will be enabled again automatically after the error
has been eliminated and acknowledged. This requires that the Enable input parameter has
retained the value TRUE during this process.
Table 10- 55 MC_Power instruction
LAD / FBD
SCL
"MC_Power_DB"(
Axis:=_multi_fb_in_,
Enable:=_bool_in_,
StartMode:=_int_in_,
StopMode:=_int_in_,
Status=>_bool_out_,
Busy=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
Description
The MC_Power motion control instruction enables
or disables an axis. Before you can enable or disable the axis, ensure the following conditions:
•
The technology object has been configured
correctly.
• There is no pending enable-inhibiting error.
The execution of MC_Power cannot be aborted by
a motion control task. Disabling the axis (input
parameter Enable = FALSE) aborts all motion control tasks for the associated technology object.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_Power_DB" is the name of the instance DB.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
733
Technology instructions
10.3 Motion control
Table 10- 56 Parameters for the MC_Power instruction
Parameter and type
Data type
Description
Axis
IN_OUT
TO_Axis
Axis technology object
Enable
IN
Bool
•
FALSE (default): All active tasks are aborted according to the parameterized "StopMode" and the axis is stopped.
•
TRUE: Motion control attempts to enable the axis.
•
0: Speed controlled
Note: The StartMode parameter is only evaluated during edge detection (false to true).
•
1: Position controlled (default)
•
0: Emergency stop: If a request to disable the axis is pending, the
axis brakes at the configured emergency deceleration. The axis is
disabled after reaching standstill.
•
1: Immediate stop: If a request to disable the axis is pending, this
axis is disabled without deceleration. Pulse output is stopped immediately.
•
2: Emergency stop with jerk control: If a request to disable the axis is
pending, the axis brakes at the configured emergency stop deceleration. If the jerk control is activated, the configured jerk is taken into
account. The axis is disabled after reaching standstill.
StartMode
StopMode
Status
IN
IN
OUT
Int
Int
Bool
Status of axis enable:
•
•
Busy
OUT
Bool
Error
OUT
Bool
FALSE: The axis is disabled:
–
The axis does not execute motion control tasks and does not accept any new tasks (exception: MC_Reset task).
–
The axis is not homed.
–
Upon disabling, the status does not change to FALSE until the
axis reaches a standstill.
TRUE: The axis is enabled:
–
The axis is ready to execute motion control tasks.
–
Upon axis enabling, the status does not change to TRUE until
the signal "Drive ready" is pending. If the "Drive ready" drive interface was not configured in the axis configuration, the status
changes to TRUE immediately.
FALSE: MC_Power is not active.
TRUE: MC_Power is active.
FALSE: No error
TRUE: An error has occurred in motion control instruction "MC_Power"
or in the associated technology object. The cause of the error can be
found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error""
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID"
S7-1200 Programmable controller
734
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
①
②
An axis is enabled and then disabled again. After the drive has signaled "Drive ready" back to the CPU, the successful enable can be read out via "Status_1".
Following an axis enable, an error has occurred that caused the axis to be disabled. The error is eliminated and
acknowledged with "MC_Reset". The axis is then enabled again.
To enable an axis with configured drive interface, follow these steps:
1. Check the requirements indicated above.
2. Initialize input parameter "StopMode" with the desired value. Set input parameter
"Enable" to TRUE.
The enable output for "Drive enabled" changes to TRUE to enable the power to the drive.
The CPU waits for the "Drive ready" signal of the drive.
When the "Drive ready" signal is available at the configured ready input of the CPU, the
axis becomes enabled. Output parameter "Status" and technology object tag .StatusBits.Enable indicates the value TRUE.
To enable an axis without configured drive interface, follow these steps:
1. Check the requirements indicated above.
2. Initialize input parameter "StopMode" with the desired value. Set input parameter
"Enable" to TRUE. The axis is enabled. Output parameter "Status" and technology object
tag .StatusBits.Enable indicate the value TRUE.
To disable an axis, follow these steps:
1. Bring the axis to a standstill.
You can identify when the axis is at a standstill in technology object tag .StatusBits.StandStill.
2. Set input parameter "Enable" to FALSE after standstill is reached.
3. If output parameters "Busy" and "Status" and technology object tag .StatusBits.Enable indicate the value FALSE, disabling of the axis is complete.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
735
Technology instructions
10.3 Motion control
10.3.7.3
MC_Reset (Confirm error)
Table 10- 57 MC_Reset instruction
LAD / FBD
SCL
"MC_Reset_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Restart:=_bool_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
Description
Use the MC_Reset instruction to acknowledge
"Operating error with axis stop" and "Configuration error". The errors that require acknowledgement can be found in the "List of ErrorIDs
and ErrorInfos" under "Remedy".
Before using the MC_Reset instruction, you
must have eliminated the cause of a pending
configuration error requiring acknowledgement
(for example, by changing an invalid acceleration value in "Axis" technology object to a valid
value).
As of V3.0 and later, the Restart command
allows the axis configuration to be downloaded
to the work memory in the RUN operating
mode.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_Reset_DB" is the name of the instance DB.
The MC_Reset task cannot be aborted by any other motion control task. The new MC_Reset
task does not abort any other active motion control tasks.
Table 10- 58 Parameters of the MC_Reset instruction
Parameter and type
Data type
Description
Axis
IN
TO_Axis_1
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge
Restart
IN
Bool
TRUE = Download the axis configuration from the load memory to the
work memory. The command can only be executed when the axis is
disabled.
Done
OUT
Bool
TRUE = Error has been acknowledged.
Busy
OUT
Bool
TRUE = The task is being executed.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task. The
cause of the error can be found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUTP
Word
Error ID for parameter "Error""
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID"
FALSE = Acknowledges pending errors
To acknowledge an error with MC_Reset, follow these steps:
1. Check the requirements indicated above.
2. Start the acknowledgement of the error with a rising edge at the Execute input parameter.
3. The error has been acknowledged when Done equals TRUE and the technology object
tag .StatusBits.Error equals FALSE.
S7-1200 Programmable controller
736
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.7.4
MC_Home (Home axis)
Table 10- 59 MC_Home instruction
LAD / FBD
SCL
"MC_Home_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Position:=_real_in_,
Mode:=_int_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_,
ReferenceMarkPosition=>_real_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_Home_DB" is the name of the instance DB.
Description
Use the MC_Home instruction to match
the axis coordinates to the real, physical
drive position. Homing is required for
absolute positioning of the axis:
In order to use the MC_Home instruction,
the axis must first be enabled.
The following types of homing are available:
● Direct homing absolute (Mode = 0): The current axis position is set to the value of
parameter "Position".
● Direct homing relative (Mode = 1): The current axis position is offset by the value of
parameter "Position".
● Passive homing (Mode = 2): During passive homing, the MC_Home instruction does not
carry out any homing motion. The traversing motion required for this step must be
implemented by the user via other motion control instructions. When the reference point
switch is detected, the axis is homed.
● Active homing (Mode = 3): The homing procedure is executed automatically.
● Absolute encoder adjustment (relative) (Mode = 6): The current position is shifted by the
value of the parameter "MC_Home.Position".
● Absolute encoder adjustment (absolute) (Mode = 7): The current position is set to the
value of the parameter "MC_Home.Position".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
737
Technology instructions
10.3 Motion control
Table 10- 60 Parameters for the MC_Home instruction
Parameter and type
Data type
Description
Axis
IN_OUT
TO_Axis
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge
Position
IN
Real
•
Mode = 0, 2, and 3 (Absolute position of axis after completion of the homing operation)
•
Mode = 1 (Correction value for the current axis position)
•
Mode = 6 (The current position is shifted by the value of
the parameter "MC_Home.Position".)
Mode = 7 (The current position is set to the value of the
parameter "MC_Home.Position".)
Limit values: -1.0e12 ≤ Position ≤ 1.0e12
•
Mode
IN
Int
Homing mode:
•
0: Direct homing absolute
New axis position is the position value of parameter "Position".
•
1: Direct homing relative
New axis position is the current axis position + position
value of parameter "Position".
•
2: Passive homing
Homing according to the axis configuration. Following
homing, the value of parameter "Position" is set as the
new axis position.
•
3: Active homing
Reference point approach in accordance with the axis
configuration. Following homing, the value of parameter
"Position" is set as the new axis position.
•
6: The current position is shifted by the value of the parameter "MC_Home.Position". The calculated absolute
value offset is stored retentively in the CPU.
(.StatusSensor.AbsEncoderOffset)
•
7: The current position is set to the value of the parameter
"MC_Home.Position". The calculated absolute value offset
is stored retentively in the CPU.
(.StatusSensor.AbsEncoderOffset)
Done
OUT
Bool
TRUE = Task completed
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution, the task was aborted by another
task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task.
The cause of the error can be found in parameters "ErrorID"
and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error""
S7-1200 Programmable controller
738
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Parameter and type
Data type
Description
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID"
ReferenceMarkPosition
OUT
Real
Position of the axis at the reference mark in the previous coordinate system.
"ReferenceMarkPosition" output parameter: The homing function saves the old position
before execution and provides this value in the ReferenceMarkPosition output parameter.
The output displays the following values during the different homing modes:
● Active/Passive homing: Displays the position of the axis at the zero/reference mark of the
previous coordinate system during and after active/passive homing.
● Absolute encoder adjustment: Displays the previous axis position during and after
absolute encoder adjustment.
● Direct homing: Displays the previous axis position during and after direct homing.
During homing, motion control sets the axis position to the new value of input
"MC_Home.Position". The values of "MC_Home.ReferenceMarkPosition" are valid when
"MC_Home.Done" = TRUE.
Note
Axis homing is lost under the following conditions
• Disabling of axis by the MC_Power instruction
• Switchover between automatic control and manual control
• Upon start of active homing (After successful completion of the homing operation, axis
homing is available again.)
• After power-cycling the CPU
• After CPU restart (RUN-to-STOP or STOP-to-RUN)
To home the axis, follow these steps:
1. Check the requirements indicated above.
2. Initialize the necessary input parameters with values, and start the homing operation with
a rising edge at input parameter "Execute".
3. If output parameter "Done" and technology object tag .StatusBits.HomingDone indicate the value TRUE, homing is complete.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
739
Technology instructions
10.3 Motion control
Table 10- 61 Override response
Mode
Description
0 or 1
The MC_Home task cannot be aborted by any other motion control task. The new MC_Home task does not
abort any active motion control tasks. Position-related motion tasks are resumed after homing according to
the new homing position (value at the Position input parameter).
2
The MC_Home task can be aborted by the following motion control tasks:
MC_Home task Mode = 2, 3: The new MC_Home task aborts the following active motion control task.
MC_Home task Mode = 2: Position-related motion tasks are resumed after homing according to the new
homing position (value at the Position input parameter).
3
The MC_Home task can be aborted by the following
motion control tasks:
10.3.7.5
The new MC_Home task aborts the following active
motion control tasks:
•
MC_Home Mode = 3
•
MC_Home Mode = 2, 3
•
MC_Halt
•
MC_Halt
•
MC_MoveAbsolute
•
MC_MoveAbsolute
•
MC_MoveRelative
•
MC_MoveRelative
•
MC_MoveVelocity
•
MC_MoveVelocity
•
MC_MoveJog
•
MC_MoveJog
MC_Halt (Pause axis)
Table 10- 62 MC_Halt instruction
LAD / FBD
SCL
"MC_Halt_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_Halt_DB" is the name of the instance DB.
Description
Use the MC_Halt instruction to stop all
motion and to bring the axis to a standstill. The stand-still position is not defined.
In order to use the MC_Halt instruction,
the axis must first be enabled.
S7-1200 Programmable controller
740
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 63 Parameters for the MC_Halt instruction
Parameter and type
Data type
Description
Axis
IN
TO_Axis_1
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge
Done
OUT
Bool
TRUE = Zero velocity reached
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution the task was aborted by another
task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task.
The cause of the error can be found in parameters "ErrorID"
and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error"
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID"
The following values were configured in the "Dynamics > General" configuration window: Acceleration = 10.0 and Deceleration = 5.0
①
②
The axis is braked by an MC_Halt task until it comes to a standstill. The axis standstill is signaled via "Done_2".
While an MC_Halt task is braking the axis, this task is aborted by another motion task. The abort is signaled via
"Abort_2".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
741
Technology instructions
10.3 Motion control
Override response
10.3.7.6
The MC_Halt task can be aborted by the
following motion control tasks:
The new MC_Halt task aborts the following
active motion control tasks:
• MC_Home Mode = 3
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveVelocity
• MC_MoveJog
• MC_MoveJog
MC_MoveAbsolute (Position axis absolutely)
Table 10- 64 MC_MoveAbsolute instruction
LAD / FBD
SCL
"MC_MoveAbsolute_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Position:=_real_in_,
Velocity:=_real_in_,
Direction:=_int_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
Description
Use the MC_MoveAbsolute instruction to start a positioning
motion of the axis to an absolute
position.
In order to use the
MC_MoveAbsolute instruction, the
axis must first be enabled and also
must be homed.
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_MoveAbsolute_DB" is the name of the instance DB.
S7-1200 Programmable controller
742
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 65 Parameters for the MC_MoveAbsolute instruction
Parameter and type
Data type
Description
Axis
IN
TO_Axis_1
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge (Default value: False)
Position
IN
Real
Absolute target position (Default value: 0.0)
Limit values: -1.0e12 ≤ Position ≤ 1.0e12
Velocity
IN
Real
Velocity of axis (Default value: 10.0)
This velocity is not always reached because of the configured acceleration and deceleration and the target position to be approached.
Limit values: Start/stop velocity ≤ Velocity ≤ maximum velocity
Direction
IN
Int
Direction of rotation (Default value: 0)
Done
OUT
Bool
TRUE = Absolute target position reached
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution the task was aborted by another task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task. The
cause of the error can be found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error" (Default value: 0000)
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID" (Default value: 0000)
You can configure the positioning axis as a Modulo axis. When using a modulo axis, you can
select the motion direction with the "Direction" input parameter. Motion control ignores the
"Direction" input if the axis is not a Modulo axis.
The following table shows the valid values for the Direction input:
Value
Enumeration
Comment
0
SIGN_OF_VELOCITY
Sign of velocity defines the motion direction
1
POSITIVE
Motion with positive velocity
2
NEGATIVE
Motion with negative velocity
3
SHORTEST_WAY
Motion with shortest distance to the destination
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
743
Technology instructions
10.3 Motion control
The following values were configured in the "Dynamics > General" configuration window: Acceleration = 10.0 and Deceleration = 10.0
①
②
An axis is moved to absolute position 1000.0 with a MC_MoveAbsolute task. When the axis reaches the target
position, this is signaled via "Done_1". When "Done_1" = TRUE, another MC_MoveAbsolute task, with target position 1500.0, is started. Because of the response times (e.g., cycle time of user program, etc.), the axis comes to a
standstill briefly (see zoomed-in detail). When the axis reaches the new target position, this is signaled via
"Done_2".
An active MC_MoveAbsolute task is aborted by another MC_MoveAbsolute task. The abort is signaled via
"Abort_1". The axis is then moved at the new velocity to the new target position 1500.0. When the new target position is reached, this is signaled via "Done_2".
Override response
The MC_MoveAbsolute task can be aborted by the following motion control tasks:
The new MC_MoveAbsolute task aborts
the following active motion control tasks:
• MC_Home Mode = 3
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveVelocity
• MC_MoveJog
• MC_MoveJog
S7-1200 Programmable controller
744
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.7.7
MC_MoveRelative (Position axis relatively)
Table 10- 66 MC_MoveRelative instruction
LAD / FBD
SCL
"MC_MoveRelative_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Distance:=_real_in_,
Velocity:=_real_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_MoveRelative_DB " is the name of the instance DB.
Description
Use the MC_MoveRelative instruction to start a positioning motion
relative to the start position.
In order to use the
MC_MoveRelative instruction, the
axis must first be enabled.
Table 10- 67 Parameters for the MC_MoveRelative instruction
Parameter and type
Axis
IN
Data type
Description
TO_Axis_1
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge (Default value: False)
Distance
IN
Real
Travel distance for the positioning operation (Default value: 0.0)
Limit values: -1.0e12 ≤ Distance ≤ 1.0e12
Velocity
IN
Real
Velocity of axis (Default value: 10.0)
This velocity is not always reached on account of the configured
acceleration and deceleration and the distance to be traveled.
Limit values: Start/stop velocity ≤ Velocity ≤ maximum velocity
Done
OUT
Bool
TRUE = Target position reached
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution the task was aborted by another task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task. The
cause of the error can be found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error" (Default value: 0000)
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID" (Default value: 0000)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
745
Technology instructions
10.3 Motion control
The following values were configured in the "Dynamics > General" configuration window: Acceleration = 10.0 and Deceleration = 10.0
①
②
The axis is moved by an MC_MoveRelative task by the distance ("Distance") 1000.0. When the axis reaches the
target position, this is signaled via "Done_1". When "Done_1" = TRUE, another MC_MoveRelative task, with travel
distance 500.0, is started. Because of the response times (for example, cycle time of user program), the axis
comes to a standstill briefly (see zoomed-in detail). When the axis reaches the new target position, this is signaled
via "Done_2".
An active MC_MoveRelative task is aborted by another MC_MoveRelative task. The abort is signaled via
"Abort_1". The axis is then moved at the new velocity by the new distance ("Distance") 500.0. When the new target
position is reached, this is signaled via "Done_2".
Override response
The MC_MoveRelative task can be aborted
by the following motion control tasks:
The new MC_MoveRelative task aborts the
following active motion control tasks:
• MC_Home Mode = 3
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveVelocity
• MC_MoveJog
• MC_MoveJog
S7-1200 Programmable controller
746
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
10.3.7.8
MC_MoveVelocity (Move axis at predefined velocity)
Table 10- 68 MC_MoveVelocity instruction
LAD / FBD
SCL
"MC_MoveVelocity_DB"(
Axis:=_multi_fb_in_,
Execute:=_bool_in_,
Velocity:=_real_in_,
Direction:=_int_in_,
Current:=_bool_in_,
PositionControlled:=_bool_in_,
InVelocity=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_MoveVelocity_DB " is the name of the instance DB.
Description
Use the MC_MoveVelocity instruction to move the axis constantly at
the specified velocity.
In order to use the
MC_MoveVelocity instruction, the
axis must first be enabled.
Table 10- 69 Parameters for the MC_MoveVelocity instruction
Parameter and type
Data type
Description
Axis
IN
TO_SpeedAxis
Axis technology object
Execute
IN
Bool
Start of the task with a positive edge (Default value: False)
Velocity
IN
Real
Velocity specification for axis motion (Default value: 100.0)
Limit values: Start/stop velocity ≤ |Velocity| ≤ maximum velocity
(Velocity = 0.0 is allowed)
Direction
Current
IN
IN
Int
Bool
Direction specification:
•
0: Direction of rotation corresponds to the sign of the value in
parameter "Velocity" (Default value)
•
1: Positive direction of rotation (The sign of the value in parameter "Velocity" is ignored.)
•
2: Negative direction of rotation (The sign of the value in parameter "Velocity" is ignored.)
Maintain current velocity:
•
FALSE: "Maintain current velocity" is deactivated. The values
of parameters "Velocity" and "Direction" are used. (Default value)
•
TRUE: "Maintain current velocity" is activated. The values in
parameters "Velocity" and "Direction" are not taken into account.
When the axis resumes motion at the current velocity, the "InVelocity" parameter returns the value TRUE.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
747
Technology instructions
10.3 Motion control
Parameter and type
PositionControlled
InVelocity
IN
OUT
Data type
Description
Bool
•
0: speed controlled
•
1: position controlled (Default value: True)
Bool
TRUE:
•
If "Current" = FALSE: The velocity specified in parameter "Velocity" was reached.
•
If "Current" = TRUE: The axis travels at the current velocity at
the start time.
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution the task was aborted by another task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task. The
cause of the error can be found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error" (Default value: 0000)
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID" (Default value: 0000)
The following values were configured in the "Dynamics > General" configuration window: Acceleration = 10.0 and Deceleration = 10.0
①
②
An active MC_MoveVelocity task signals via "InVel_1" that its target velocity has been reached. It is then aborted
by another MC_MoveVelocity task. The abort is signaled via "Abort_1". When the new target velocity 15.0 is
reached, this is signaled via "InVel_2". The axis then continues moving at the new constant velocity.
An active MC_MoveVelocity task is aborted by another MC_MoveVelocity task prior to reaching its target velocity.
The abort is signaled via "Abort_1". When the new target velocity 15.0 is reached, this is signaled via "InVel_2".
The axis then continues moving at the new constant velocity.
S7-1200 Programmable controller
748
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Override response
The MC_MoveVelocity task can be aborted
by the following motion control tasks:
The new MC_MoveVelocity task aborts the
following active motion control tasks:
• MC_Home Mode = 3
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveVelocity
• MC_MoveJog
• MC_MoveJog
Note
Behavior with zero set velocity (Velocity = 0.0)
An MC_MoveVelocity task with "Velocity" = 0.0 (such as an MC_Halt task) aborts active
motion tasks and stops the axis with the configured deceleration. When the axis comes to a
standstill, output parameter "InVelocity" indicates TRUE for at least one program cycle.
"Busy" indicates the value TRUE during the deceleration operation and changes to FALSE
together with "InVelocity". If parameter "Execute" = TRUE is set, "InVelocity" and "Busy" are
latched.
When the MC_MoveVelocity task is started, status bit "SpeedCommand" is set in the
technology object. Status bit "ConstantVelocity" is set upon axis standstill. Both bits are
adapted to the new situation when a new motion task is started.
10.3.7.9
MC_MoveJog (Move axis in jog mode)
Table 10- 70 MC_MoveJog instruction
LAD / FBD
SCL
"MC_MoveJog_DB"(
Axis:=_multi_fb_in_,
JogForward:=_bool_in_,
JogBackward:=_bool_in_,
Velocity:=_real_in_,
PositionControlled:=_bool_in_,
InVelocity=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_MoveJog_DB " is the name of the instance DB.
Description
Use the MC_MoveJog instruction to move
the axis constantly at the specified velocity in jog mode. This instruction is typically
used for testing and commissioning purposes.
In order to use the MC_MoveJog instruction, the axis must first be enabled.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
749
Technology instructions
10.3 Motion control
Table 10- 71 Parameters for the MC_MoveJog instruction
Parameter and type
Data type
Description
Axis
IN
TO_SpeedAxis
Axis technology object
JogForward1
IN
Bool
As long as the parameter is TRUE, the axis moves in the positive
direction at the velocity specified in parameter "Velocity". The sign of
the value in parameter "Velocity" is ignored. (Default value: False)
JogBackward1
IN
Bool
As long as the parameter is TRUE, the axis moves in the negative
direction at the velocity specified in parameter "Velocity". The sign of
the value in parameter "Velocity" is ignored. (Default value: False)
Velocity
IN
Real
Preset velocity for jog mode (Default value: 100.0)
Limit values: Start/stop velocity ≤ |Velocity| ≤ maximum velocity
PositionControlled
IN
Bool
•
0: speed controlled
•
1: position controlled (Default value: True)
InVelocity
OUT
Bool
TRUE = The velocity specified in parameter "Velocity" was reached.
Busy
OUT
Bool
TRUE = The task is being executed.
CommandAborted
OUT
Bool
TRUE = During execution the task was aborted by another task.
Error
OUT
Bool
TRUE = An error has occurred during execution of the task. The
cause of the error can be found in parameters "ErrorID" and "ErrorInfo".
ErrorID
OUT
Word
Error ID for parameter "Error" (Default value: 0000)
ErrorInfo
OUT
Word
Error info ID for parameter "ErrorID" (Default value: 0000)
1
If both the JogForward and JogBackward parameters are simultaneously TRUE, the axis stops with the configured
deceleration. An error is indicated in parameters "Error", "ErrorID", and "ErrorInfo".
The following values were configured in the "Dynamics > General" configuration window: Acceleration = 10.0 and Deceleration = 5.0
①
②
The axis is moved in the positive direction in jog mode via "Jog_F". When the target velocity 50.0 is reached, this is
signaled via "InVelo_1". The axis brakes to a standstill again after Jog_F is reset.
The axis is moved in the negative direction in jog mode via "Jog_B". When the target velocity 50.0 is reached, this
is signaled via "InVelo_1". The axis brakes to a standstill again after Jog_B is reset.
S7-1200 Programmable controller
750
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Override response
10.3.7.10
The MC_MoveJog task can be aborted by
the following motion control tasks:
The new MC_MoveJog task aborts the
following active motion control tasks:
• MC_Home Mode = 3
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveVelocity
• MC_MoveJog
• MC_MoveJog
MC_CommandTable (Run axis commans as movement sequence)
Table 10- 72 MC_CommandTable instruction
LAD / FBD
SCL
"MC_CommandTable_DB"(
Axis:=_multi_fb_in_,
CommandTable:=_multi_fb_in_,
Execute:=_bool_in_,
StartIndex:=_uint_in_,
EndIndex:=_uint_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
CommandAborted=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_,
CurrentIndex=>_uint_out_,
Code=>_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_CommandTable_DB " is the name of the instance DB.
Description
Executes a series of individual
motions for a motor control axis
that can combine into a movement sequence.
Individual motions are configured
in a technology object command
table for pulse train output
(TO_CommandTable_PTO).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
751
Technology instructions
10.3 Motion control
Table 10- 73 Parameters for the MC_CommandTable instruction
Parameter and type
Data type
Initial value
Description
Axis
IN
TO_Axis_1
-
Axis technology object
Table
IN
TO_CommandTable_1
-
Command table technology object
Execute
IN
Bool
FALSE
Start job with rising edge
StartIndex
IN
Int
1
Start command table processing with this step
Limits: 1 ≤ StartIndex ≤ EndIndex
EndIndex
IN
Int
32
End command table processing with this step
Limits: StartIndex ≤ EndIndex ≤ 32
Done
OUT
Bool
FALSE
MC_CommandTable processing completed successfully
Busy
OUT
Bool
FALSE
Operation in progress
CommandAborted
OUT
Bool
FALSE
The task was aborted during processing by another task.
Error
OUT
Bool
FALSE
An error occurred during processing. The cause is
indicated by the parameters ErrorID and ErrorInfo.
ErrorID
OUT
Word
16#0000
Error identifier
ErrorInfo
OUT
Word
16#0000
Error information
Step
OUT
Int
0
Step currently in process
Code
OUT
Word
16#0000
User defined identifier of the step currently in process
You can create the desired movement sequence in the "Command Table" configuration
window and check the result against the graphic view in the trend diagram.
You can select the command types that are to be used for processing the command table.
Up to 32 jobs can be entered. The commands are processed in sequence.
S7-1200 Programmable controller
752
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 74 MC_CommandTable command types
Command type
Description
Empty
The empty serves as a placeholder for any commands to be added. The empty entry is
ignored when the command table is processed
Halt
Pause axis.
Note: The command only takes place after a "Velocity setpoint" command.
Positioning Relative
Positions the axis based upon distance. The command moves the axis by the given distance and velocity.
Positioning Absolute
Positions the axis based upon location. The command moves the axis to the given location, using the velocity specified.
Velocity setpoint
Moves the axis at the given velocity.
Wait
Waits until the given period is over. "Wait" does not stop an active traversing motion.
Separator
Adds a "Separator" line above the selected line. The separator line allows more than one
profile to be defined in a single command table.
Prerequisites for MC_CommandTable execution:
● The technology object TO_Axis_PTO V2.0 must be correctly configured.
● The technology object TO_CommandTable_PTO must be correctly configured.
● The axis must be released.
Override response
The MC_CommandTable task can be
aborted by the following motion control
tasks:
The new MC_CommandTable task aborts the
following active motion control tasks:
• MC_Home Mode = 3
• MC_Halt
• MC_Halt
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveJog
• MC_CommandTable
• MC_Home Mode = 3
• MC_MoveAbsolute
• MC_MoveRelative
• MC_MoveVelocity
• MC_MoveJog
• MC_CommandTable
• The current motion control job with the
launch of the first "Positioning Relative",
"Positioning Absolute", "Velocity setpoint"
or "Halt" command
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
753
Technology instructions
10.3 Motion control
10.3.7.11
MC_ChangeDynamic (Change dynamc settings for the axis)
Table 10- 75 MC_ChangeDynamic instruction
LAD / FBD
SCL
"MC_ChangeDynamic_DB"(
Execute:=_bool_in_,
ChangeRampUp:=_bool_in_,
RampUpTime:=_real_in_,
ChangeRampDown:=_bool_in_,
RampDownTime:=_real_in_,
ChangeEmergency:=_bool_in_,
EmergencyRampTime:=_real_in_,
ChangeJerkTime:=_bool_in_,
JerkTime:=_real_in_,
Done=>_bool_out_,
Error=>_bool_out_,
ErrorID=>_word_out_,
ErrorInfo=>_word_out_);
Description
Changes the dynamic settings of
a motion control axis:
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_ChangeDynamic_DB " is the name of the instance DB.
•
Change the ramp-up time
(acceleration) value
•
Change the ramp-down time
(deceleration) value
•
Change the emergency stop
ramp-down time (emergency
stop deceleration) value
•
Change the smoothing time
(jerk) value
S7-1200 Programmable controller
754
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 76 Parameters for the MC_ChangeDynamic instruction
Parameter and type
Data type
Description
Axis
IN
TO_Axis_1
Axis technology object
Execute
IN
Bool
Start of the command with a positive edge. Default value:
FALSE
ChangeRampUp
IN
Bool
TRUE = Change ramp-up time in line with input parameter
"RampUpTime". Default value: FALSE
RampUpTime
IN
Real
Time (in seconds) to accelerate from standstill to the configured
maximum velocity without jerk limit. Default value: 5.00
The change will influence the tag . Config.DynamicDefaults.Acceleration. The effectiveness of the
change is shown in the description of this tag.
ChangeRampDown
IN
Bool
TRUE = Change ramp-down time in line with input parameter
"RampDownTime". Default value: FALSE
RampDownTime
IN
Real
Time (in seconds) to decelerate axis from the configured maximum velocity to standstill without jerk limiter. Default value: 5.00
The change will influence the tag . Config.DynamicDefaults.Deceleration. The effectiveness of the
change is shown in the description of this tag.
ChangeEmergency
IN
Bool
TRUE = Change emergency stop ramp-down time in line with
input parameter "EmergencyRampTime" Default value: FALSE
EmergencyRampTime
IN
Real
Time (in seconds) to decelerate the axis from configured maximum velocity to standstill without jerk limiter in emergency stop
mode. Default value: 2.00
The change will influence the tag . Config.DynamicDefaults.EmergencyDeceleration. The effectiveness
of the change is shown in the description of this tag.
ChangeJerkTime
IN
Bool
TRUE = Change smoothing time according to the input parameter "JerkTime". Default value: FALSE
JerkTime
IN
Real
Smoothing time (in seconds) used for the axis acceleration and
deceleration ramps. Default value: 0.25
The change will influence the tag . Config.DynamicDefaults.Jerk. The effectiveness of the change is
shown in the description of this tag.
Done
OUT
Bool
TRUE = The changed values have been written to the technology data block. The description of the tags will show when the
change becomes effective. Default value: FALSE
Error
OUT
Bool
TRUE = An error occurred during execution of the command.
The cause of the error can be found in parameters "ErrorID" and
"ErrorInfo". Default value: FALSE
ErrorID
OUT
Word
Error identifier. Default value: 16#0000
ErrorInfo
IN
Word
Error information. Default value: 16#0000
Prerequisites for MC_ ChangeDynamic execution:
● The technology object TO_Axis_PTO V2.0 must be correctly configured.
● The axis must be released.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
755
Technology instructions
10.3 Motion control
Note
You can only use the MC_ChangeDynamic instruction for a drive connection using PTO
(Pulse Train Output).
Override response
An MC_ChangeDynamic command cannot be aborted by any other motion control
command.
A new MC_ChangeDynamic command does not abort any active motion control jobs.
Note
The input parameters "RampUpTime", "RampDownTime", "EmergencyRampTime" and
"RoundingOffTime" can be specified with values that makes the resultant axis parameters
"acceleration", "delay", "emergency stop-delay" and "jerk" outside the permissible limits.
Make sure you keep the MC_ChangeDynamic parameters within the limits of the dynamic
configuration settings for the axis technology object.
10.3.7.12
MC_WriteParam (write parameters of a technology object)
You use the MC_WriteParam instruction to write a select number of parameters to change
the functionality of the axis from the user program.
Table 10- 77 MC_WriteParam instruction
LAD / FBD
SCL
"MC_WriteParam_DB"(
Parameter:=_variant_in_,
Value:=_variant_in_,
Execute:=_bool_in_,
Done:=_bool_out_,
Error:=_real_out_,
ErrorID:=_word_out_,
ErrorInfo:=_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_WriteParam_DB" is the name of the instance DB.
Description
You use the MC_WriteParam
instruction to write to public parameters (for example, acceleration and user DB values).
S7-1200 Programmable controller
756
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
You can write to the parameters that are public. You cannot write to "MotionStatus" and
"StatusBits". The valid parameters are listed in the table below:
Writeable parameter name
Writeable parameter name
Actor.InverseDirection
DynamicDefaults.Acceleration
Actor.DirectionMode
DynamicDefaults.Deceleration
Actor.DriveParameter.PulsesPerDriveRevolution
DynamicDefaults.Jerk
Sensor[1].ActiveHoming.Mode
DynamicDefaults.EmergencyDeceleration
Sensor[1].ActiveHoming.SideInput
PositionLimitsHW.Active
Sensor[1].ActiveHoming.Offset
PositionLimitsHW.MaxSwitchedLevel
Sensor[1].ActiveHoming.SwitchedLevel
PositionLimitsHW.MinSwitchedLevel
Sensor[1].PassiveHoming.Mode
PositionLimitsSW.Active
Sensor[1].PassiveHoming.SideInput
PositionLimitsSW.MinPosition
Sensor[1].PassiveHoming.SwitchedLevel
PositionLimitsSW.MaxPosition
Units.LengthUnit
Homing.AutoReversal
Mechanics.LeadScrew
Homing.ApproachDirection
DynamicLimits.MinVelocity
Homing.ApproachVelocity
DynamicLimits.MaxVelocity
Homing.ReferencingVelocity
Table 10- 78 Parameters for the MC_WriteParam instruction
Parameter and type
Data type
Description
PARAMNAME
IN
Variant
Name of parameter where value is written
VALUE
IN
Variant
Value to write to assigned parameter
EXECUTE
IN
Bool
Start the instruction. Default value: FALSE
DONE
OUT
Bool
Value has been written. Default value: FALSE
BUSY
OUT
Bool
If TRUE, the instruction is operating. Default value: FALSE
ERROR
OUT
Real
If TRUE, an error occurred. Default value: FALSE
ERRORID
OUT
Word
ID of the error
ERRORINFO
OUT
Word
Related information to the ERRORID
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
757
Technology instructions
10.3 Motion control
Table 10- 79 Condition codes for ERRORID and ERRORINFO
ERRORID
ERRORINFO
Description
(W#16#...)
(W#16#...)
0
0
Successful change of an Axis TO-DB parameter
8410[1]
0028[1]
Set an invalid parameter (Axis TO-DB parameter with incorrect length)
8410[1]
0029[1]
Set an invalid parameter (no Axis TO-DB parameter)
8410[1]
002B[1]
Set an Invalid parameter (read-only Axis TO-DB parameter)
8410[1]
002C[1]
Set a valid parameter, but axis is not disabled
Config
Error[2]
Config
Error[2]
Set a valid parameter (public read-only Axis TO-DB parameter) out-of-range
Config
Error[3]
Config
Error[3]
Set a valid parameter (public Axis TO-DB parameter) out-of-range
[1] Error at MC_WriteParam
[2] Error at MC_Power
[3] Error at MC_Power and MC_MoveXXX or MC_CommandTable
Note
For a drive connection using a PROFIdrive/analog output, you cannot write parameters with
MC_WriteParam that require a restart of the technology object. The TIA Portal online help
statement concerning this instruction is incorrect.
10.3.7.13
MC_ReadParam instruction (read parameters of a technology object)
You use the MC_ReadParam instruction to read a select number of parameters that indicate
the current position, velocity, and so forth of the axis defined in the Axis input.
Table 10- 80 MC_ReadParam instruction
LAD / FBD
SCL
"MC_ReadParam_DB"(
Enable:=_bool_in_,
Parameter:=_variant_in_,
Value:=_variant_in_out_,
Valid:=_bool_out_,
Busy:=_bool_out_,
Error:=_real_out_,
ErrorID:=_word_out_,
ErrorInfo:=_word_out_);
1
STEP 7 automatically creates the DB when you insert the instruction.
2
In the SCL example, "MC_ReadParam_DB " is the name of the instance DB.
Description
You use the MC_ReadParam
instruction to read single status
values, independent of the cycle
control point.
S7-1200 Programmable controller
758
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
The MC_ReadParam instruction works on an enable behavior. As long as the input "Enable"
is true the instruction reads the specified "Parameter" to the "Value" storage location.
The "MotionStatus" "Position" value updates at each Cycle Control Point (CCP) based upon
the current HSC value.
The "MotionStatus" "Velocity" value is the command velocity at the end of the current
segment (updated ~10ms). The MC_ReadParam can also read this value.
If an error occurs, the instruction switches to an error state that can only be reset by a new
rising edge at the input "Enable".
Table 10- 81 Parameters for the MC_ReadParam instruction
Parameter and type
Data type
Description
ENABLE
IN
Bool
Start the instruction. Default value: FALSE
PARAMETER
IN
Variant
Pointer to the TO-parameter that is to be read
VALID
OUT
Bool
If TRUE, the value has been read. Default value: FALSE
BUSY
OUT
Bool
If TRUE, the instruction is operating. Default value: FALSE
ERROR
OUT
Real
If TRUE, an error occurred. Default value: FALSE
ERRORID
OUT
Word
ID of the error. Default value: 0
ERRORINFO
OUT
Word
Related information to the ERRORID. Default value: 0
VALUE
INOUT Variant
Pointer to the location where the read value is stored
Table 10- 82 Condition codes for ERRORID and ERRORINFO
ERRORID
ERRORINFO
Description
(W#16#...)
(W#16#...)
0
0
Successful read of a parameter
8410
0028
Invalid parameter (incorrect length)
8410
0029
Invalid parameter (no TO-DB)
8410
0030
Invalid parameter (not readable)
8411
0032
Invalid parameter (wrong value)
TO parameters
The axis "MotionStatus" consists of four values. You will want to monitor changes in these
values, which can be read while the program is running:
Variable name
MotionStatus:
Data type
Readable through
MC_ReadParam
Structure
No
Yes
•
Position
REAL
•
Velocity
REAL
Yes
•
Distance
REAL
Yes
•
TargetPosition
REAL
Yes
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
759
Technology instructions
10.3 Motion control
10.3.8
Monitoring active commands
10.3.8.1
Monitoring MC instructions with a "Done" output parameter
Motion control instructions with the output parameter "Done" are started by the input
parameter "Execute" and have a defined conclusion (for example, with motion control
instruction "MC_Home": Homing was successful). The task is complete and the axis is at a
standstill.
● The output parameter "Done" indicates the value TRUE, if the task has been successfully
completed.
● The output parameters "Busy", "CommandAborted", and "Error" signal that the task is still
being processed, has been aborted or an error is pending. The motion control instruction
"MC_Reset" cannot be aborted and thus has no "CommandAborted" output parameter.
– During processing of the motion control task, the output parameter "Busy" indicates
the value TRUE. If the task has been completed, aborted, or stopped by an error, the
output parameter "Busy" changes its value to FALSE. This change occurs regardless
of the signal at input parameter "Execute".
– Output parameters "Done", "CommandAborted", and "Error" indicate the value TRUE
for at least one cycle. These status messages are latched while input parameter
"Execute" is set to TRUE.
The tasks of the following motion control instructions have a defined conclusion:
● MC_Reset
● MC_Home
● MC_Halt
● MC_MoveAbsolute
● MC_MoveRelative
S7-1200 Programmable controller
760
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
The behavior of the status bits is presented below for various example situations.
● The first example shows the behavior of the axis for a completed task. If the motion
control task has been completely executed by the time of its conclusion, this is indicated
by the value TRUE in output parameter "Done". The signal status of input parameter
"Execute" influences the display duration in the output parameter "Done".
● The second example shows the behavior of the axis for an aborted task. If the motion
control task is aborted during execution, this is indicated by the value TRUE in output
parameter "CommandAborted". The signal status of the input parameter "Execute"
influences the display duration in the output parameter "CommandAborted".
● The third example shows the behavior of the axis if an error occurs. If an error occurs
during execution of the motion control task, this is indicated by the value TRUE in the
output parameter "Error". The signal status of the input parameter "Execute" influences
the display duration in the output parameter "Error".
Table 10- 83 Example 1 - Complete execution of task
If "Execute" = FALSE during the processing of the task
If "Execute" = FALSE after completion of the task
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can still be reset to the value FALSE during the task, or the value TRUE can be retained until after completion of the task.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ With conclusion of the task (for example, for motion control instruction "MC_Home": Homing was successful), output
parameter "Busy" changes to FALSE and "Done" to TRUE.
④ If "Execute" retains the value TRUE until after completion of the task, then "Done" also remains TRUE and changes its
value to FALSE together with "Execute".
⑤ If "Execute" has been set to FALSE before the task is complete, "Done" indicates the value TRUE for only one execution cycle.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
761
Technology instructions
10.3 Motion control
Table 10- 84 Example 2 - Aborting the task
If "Execute" = FALSE before the task is aborted
If "Execute" = FALSE after the task is aborted
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can still be reset to the value FALSE during the task, or the value TRUE can be retained until after completion of the task.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ During task execution, the task is aborted by another motion control task. If the task is aborted, output parameter
"Busy" changes to FALSE and "CommandAborted" to TRUE.
④ If "Execute" retains the value TRUE until after the task is aborted, then "CommandAborted" also remains TRUE and
changes its value to FALSE together with "Execute".
⑤ If "Execute" has been set to FALSE before the task is aborted, "CommandAborted" indicates the value TRUE for only
one execution cycle.
S7-1200 Programmable controller
762
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 85 Example 3 - Error during task execution
If "Execute" = FALSE before the error occurs
If "Execute" = FALSE after the error occurs
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can still be reset to the value FALSE during the task, or the value TRUE can be retained until after completion of the task.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ An error occurred during task execution. When the error occurs, the output parameter "Busy" changes to FALSE and
"Error" to TRUE.
④ If "Execute" retains the value TRUE until after the error occurs, then "Error" also remains TRUE and only changes its
value to FALSE together with "Execute".
⑤ If "Execute" has been set to FALSE before the error occurs, "Error" indicates the value TRUE for only one execution
cycle.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
763
Technology instructions
10.3 Motion control
10.3.8.2
Monitoring the MC_Velocity
The tasks of the motion control instruction "MC_MoveVelocity" implement a move at the
specified velocity:
● The tasks of motion control instruction "MC_MoveVelocity" do not have a defined end.
The task objective is fulfilled when the parameterized velocity is reached for the first time
and the axis travels at constant velocity. When the parameterized velocity is reached, this
is indicated by the value TRUE in output parameter "InVelocity".
● The task is complete when the parameterized velocity has been reached and input
parameter "Execute" has been set to the value FALSE. However, the axis motion is not
yet complete upon completion of the task. For example, the axis motion can be stopped
with motion control task "MC_Halt".
● The output parameters "Busy", "CommandAborted", and "Error" signal that the task is still
being processed, has been aborted or an error is pending.
– During execution of the motion control task, output parameter "Busy" indicates the
value TRUE. If the task has been completed, aborted, or stopped by an error, the
output parameter "Busy" changes its value to FALSE. This change occurs regardless
of the signal at input parameter "Execute".
– The output parameters "InVelocity", "CommandAborted", and "Error" indicate the
value TRUE for at least one cycle, when their conditions are met. These status
messages are latched while input parameter "Execute" is set to TRUE.
The behavior of the status bits is presented below for various example situations:
● The first example shows the behavior when the axis reaches the parameterized velocity.
If the motion control task has been executed by the time the parameterized velocity is
reached, this is indicated by the value TRUE in output parameter "InVelocity". The signal
status of the input parameter "Execute" influences the display duration in the output
parameter "InVelocity".
● The second example shows the behavior if the task is aborted before achieving the
parameterized velocity. If the motion control task is aborted before the parameterized
velocity is reached, this is indicated by the value TRUE in output parameter
"CommandAborted". The signal status of input parameter "Execute" influences the
display duration in output parameter "CommandAborted".
● The third example shows the behavior of the axis if an error occurs before achieving the
parameterized velocity. If an error occurs during execution of the motion control task
before the parameterized velocity has been reached, this is indicated by the value TRUE
in the output parameter "Error". The signal status of the input parameter "Execute"
influences the display duration in the output parameter "Error".
S7-1200 Programmable controller
764
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 86 Example 1 - If the parameterized velocity is reached
If "Execute" = FALSE before the configured velocity is
reached
If "Execute" = FALSE after the configured velocity is
reached
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can be reset to the value FALSE event before the parameterized velocity is reached, or alternatively only after it has been
reached.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ When the parameterized velocity is reached, the output parameter "InVelocity" changes to TRUE.
④ If "Execute" retains the value TRUE even after the parameterized velocity has been reached, the task remains active.
"InVelocity" and "Busy" retain the value TRUE and only change their status to FALSE together with "Execute".
⑤ If "Execute" has been reset to FALSE before the parameterized velocity is reached, the task is complete when the
parameterized velocity is reached. "InVelocity" indicates the value TRUE for one execution cycle and changes to FALSE
together with "Busy".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
765
Technology instructions
10.3 Motion control
Table 10- 87 Example 2 - If the task is aborted prior to reaching the parameterized velocity
If "Execute" = FALSE before the task is aborted
If "Execute" = FALSE after the task is aborted
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can still be reset to the value FALSE during the task, or the value TRUE can be retained until after the task is aborted.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ During task execution, the task is aborted by another motion control task. If the task is aborted, output parameter
"Busy" changes to FALSE and "CommandAborted" to TRUE.
④ If "Execute" retains the value TRUE until after the task is aborted, then "CommandAborted" also remains TRUE and
changes its status to FALSE together with "Execute".
⑤ If "Execute" has been reset to FALSE before the task is aborted, "CommandAborted" indicates the value TRUE for only
one execution cycle.
Note
Under the following conditions, an abort is not indicated in output parameter
"CommandAborted":
• The parameterized velocity has been reached, input parameter "Execute" has the value
FALSE, and a new motion control task is initiated.
• When the parameterized velocity is reached and input parameter "Execute" has the value
FALSE, the task is complete. Therefore, the start of a new task is not indicated as an
abort.
S7-1200 Programmable controller
766
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 88 Example 3 - If an error occurs prior to reaching the parameterized velocity
If "Execute" = FALSE before the error occurs
If "Execute" = FALSE after the error occurs
① The task is started with a positive edge at the input parameter "Execute". Depending on the programming, "Execute"
can still be reset to the value FALSE during the task, or the value TRUE can be retained until after the error has occurred.
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ An error occurred during task execution. When the error occurs, the output parameter "Busy" changes to FALSE and
"Error" to TRUE.
④ If "Execute" retains the value TRUE until after the error has occurred, then "Error" also remains TRUE and only changes its status to FALSE together with "Execute".
⑤ If "Execute" has been reset to FALSE before the error occurs, "Error" indicates the value TRUE for only one execution
cycle.
Note
Under the following conditions, an error is not indicated in output parameter "Error":
• The parameterized velocity has been reached, input parameter "Execute" has the value
FALSE, and an axis error occurs (software limit switch is approached, for example).
• When the parameterized velocity is reached and input parameter "Execute" has the value
FALSE, the task is complete. After completion of the task, the axis error is only indicated
in the motion control instruction "MC_Power".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
767
Technology instructions
10.3 Motion control
10.3.8.3
Monitoring the MC_MoveJog
The tasks of motion control instruction "MC_MoveJog" implement a jog operation.
● The motion control tasks "MC_MoveJog" do not have a defined end. The task objective is
fulfilled when the parameterized velocity is reached for the first time and the axis travels
at constant velocity. When the parameterized velocity is reached, this is indicated by the
value TRUE in output parameter "InVelocity".
● The order is complete when input parameter "JogForward" or "JogBackward" has been
set to the value FALSE and the axis has come to a standstill.
● The output parameters "Busy", "CommandAborted", and "Error" signal that the task is still
being processed, has been aborted or an error is pending.
– During processing of the motion control task, the output parameter "Busy" indicates
the value TRUE. If the task has been completed, aborted, or stopped by an error, the
output parameter "Busy" changes its value to FALSE.
– The output parameter "InVelocity" indicates the status TRUE, as long as the axis is
moving at the parameterized velocity. The output parameters "CommandAborted" and
"Error" indicate the status for at least one cycle. These status messages are latched
as long as either input parameter "JogForward" or "JogBackward" is set to TRUE.
The behavior of the status bits is presented below for various example situations.
● The first example shows the behavior or the axis if the parameterized velocity is reached
and maintained. If the motion control task has been executed by the time the
parameterized velocity is reached, this is indicated by the value TRUE in output
parameter "InVelocity".
● The second example shows the behavior of the axis if the task is aborted. If the motion
control task is aborted during execution, this is indicated by the value TRUE in output
parameter "CommandAborted". The behavior is independent of whether or not the
parameterized velocity has been reached.
● The third example shows the behavior of the axis if an error occurs. If an error occurs
during execution of the motion control task, this is indicated by the value TRUE in output
parameter "Error". The behavior is independent of whether or not the parameterized
velocity has been reached.
S7-1200 Programmable controller
768
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 89 Example 1 - If the parameterized velocity is reached and maintained
JogForward
JogBackward
① The task is started with a positive edge at the input parameter "JogForward" or "JogBackward".
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ When the parameterized velocity is reached, the output parameter "InVelocity" changes to TRUE.
④ When the input parameter "JogForward" or "JogBackward" is reset to the value FALSE, the axis motion ends. The axis
starts to decelerate. As a result, the axis no longer moves at constant velocity and the output parameter "InVelocity"
changes its status to FALSE.
⑤ If the axis has come to a standstill, the motion control task is complete and the output parameter "Busy" changes its
value to FALSE.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
769
Technology instructions
10.3 Motion control
Table 10- 90 Example 2 - If the task is aborted during execution
JogForward
JogBackward
① The task is started with a positive edge at the input parameter "JogForward" or "JogBackward".
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ During task execution, the task is aborted by another motion control task. If the task is aborted, output parameter
"Busy" changes to FALSE and "CommandAborted" to TRUE.
④ When the input parameter "JogForward" or "JogBackward" is reset to the value FALSE, the output parameter "CommandAborted" changes its value to FALSE.
Note
The task abort is indicated in the output parameter "CommandAborted" for only one
execution cycle, if all conditions below are met:
The input parameters "JogForward" and "JogBackward" have the value FALSE (but the axis
is still decelerating) and a new motion control task is initiated.
S7-1200 Programmable controller
770
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Table 10- 91 Example 3 - If an error has occurred during task execution
JogBackward
JogForward
① The task is started with a positive edge at the input parameter "JogForward" or "JogBackward".
② While the task is active, the output parameter "Busy" indicates the value TRUE.
③ An error occurred during task execution. When the error occurs, the output parameter "Busy" changes to FALSE and
"Error" to TRUE.
④ When the input parameter "JogForward" or "JogBackward" is reset to the value FALSE, the output parameter "Error"
changes its value to FALSE.
Note
An error occurrence is indicated in the output parameter "Error" for only one execution cycle,
if all the conditions below are met:
The input parameters "JogForward" and "JogBackward" have the value FALSE (but the axis
is still decelerating) and a new error occurs (software limit switch is approached, for
example).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
771
Technology instructions
10.3 Motion control
10.3.9
ErrorIDs and ErrorInfos for motion control
The following table lists all ErrorIDs and ErrorInfos that can be indicated in motion control
instructions and data adaptation. In addition to the cause of the error, remedies for
eliminating the error are also listed.
Depending on the error reaction, the axis is stopped in the case of operating errors with stop
of axis. The following error reactions are possible:
● Remove enable
The setpoint zero is output and the enable is removed. The axis is braked depending on
the configuration in the drive, and is brought to a standstill.
● Stop with emergency stop ramp
Active motion commands are aborted. The axis is braked with the emergency stop
deceleration configured under "Technology object > Extended parameters > Dynamics >
Emergency stop ramp" without any jerk limit and brought to a standstill.
Operating error with axis stop
ErrorID
ErrorInfo
Description
16#0001
-
16#8000
Remedy
Error reaction
Drive error, loss of "Drive ready"
16#8001
Acknowledge error with instruction
"MC_Reset"; provide drive signal; restart command, if necessary
Low SW limit switch has been tripped
16#000E The position of the low SW limit
Acknowledge the error with instruction
switch was reached with the currently "MC_Reset"; use a motion command to
move the axis in the positive direction
configured deceleration
out of the range of the SW limit switch
16#000F The position of the low SW limit
Stop with emergency stop ramp.
switch was reached with the emergency stop deceleration
16#0010
16#8002
The position of the low SW limit
switch was exceeded with the emergency stop deceleration
High SW limit switch has been tripped
16#000E The position of the high SW limit
Acknowledge the error with instruction
switch was reached with the currently "MC_Reset"; use a motion command to
configured deceleration
move the axis in the negative direction
out of the range of the SW limit switch
16#000F The position of the high SW limit
Stop with emergency stop ramp.
switch was reached with the emergency stop deceleration
16#0010
The position of the high SW limit
switch was exceeded with the emergency stop deceleration
S7-1200 Programmable controller
772
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8003
Description
Remedy
Low HW limit switch was reached
16#000E The low HW limit switch was
reached. The axis was stopped with
the emergency stop deceleration.
(During an active homing procedure,
the homing switch was not found)
Error reaction
For drive connection via PTO
(Pulse Train Output):
Acknowledge the error for an enabled
axis with instruction "MC_Reset"; use a
motion command to move the axis in
the positive direction out of the range of Stop with emergency stop ramp.
the HW limit switch.
For drive connection via
PROFIdrive/analo
g output:
Remove enable.
16#8004
High HW limit switch was reached
16#000E The high HW limit switch has been
reached. The axis was stopped with
the emergency stop deceleration.
(During an active homing procedure,
the homing switch was not found)
Acknowledge the error for an enabled
axis with instruction "MC_Reset"; use a
motion command to move the axis in
the negative direction out of the range
of the HW limit switch.
For drive connection via PTO
(Pulse Train Output):
Stop with emergency stop ramp.
For drive connection via
PROFIdrive/analo
g output:
Remove enable.
16#8005
PTO/HSC are already being used by another axis
16#0001
-
-
The axis was configured incorrectly:
Correct the configuration of the PTO
(Pulse Train Output) / HSC (High
Speed Counter) and download it to the
controller
More than one axis is to run with one
PTO:
Another axis is using the PTO / HSC. If
the current axis is to assume the control, the other axis must be disabled
with "MC_Power" Enable = FALSE.
16#8006
A communication error in the control panel has occurred
16#0012
16#8007
A timeout has occurred
Remove enable.
Check the cable connection and press
the "Manual control" button again
The axis cannot be enabled
-
16#0025
Restarting
Wait until the axis restart is complete.
16#0026
Executing loading process in RUN
mode
Wait until the loading process is complete.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
773
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8008
Description
Remedy
Error reaction
Invalid direction of motion
-
16#002E The selected motion direction is not
allowed.
•
16#002F
Adjust the motion direction and
restart the command.
•
Adjust the allowed direction of rotation in the technology object configuration under "Extended parameters
> Mechanics". Restart the command.
16#8009
A reversing motion is not possible
with the selected motion direction.
Reference switch/encoder zero mark not found
16#0033
16#800A
Error in the configuration, hardware
•
or installation of the encoder or at the
•
homing switch.
•
Stop with emergency stop ramp.
Connect a suitable device.
Check the device (I/Os).
Compare the configuration of HW
Config and the technology object.
Alarm message from encoder
16#0001
-
16#0034
Hardware error at encoder
Remove enable.
Check the device with regard to function, connections and I/Os.
16#0035
Encoder dirty
16#0036
Error during reading of encoder abso- Compare the encoder type in the drive
lute value
or encoder parameter P979 with the
configuration data of the technology
object.
16#0037
Zero mark monitoring of the encoder
Encoder reports error in zero mark
monitoring (fault code 0x0002 in
Gx_XIST2, see PROFIdrive profile).
Check the plant for electromagnetic
compatibility (EMC).
16#0038
Encoder is in "Parking" state
16#0040
PROFIdrive: Encoder at bus failed
(station failure)
16#0041
PROFIdrive: Signs of life of encoder
faulty
16#0039
Range violation in positive direction
16#800B
•
Search for the cause of the error in
the connected drive or encoder.
•
Check whether the error message
was possibly triggered by a commissioning action at the drive or encoder.
Check the device with regard to function, connections and I/Os.
Range violation of the position
16#003A Range violation in negative direction
Remove enable.
Home the axis to a valid actual value
range.
16#003B The change of the actual position in a Adjust the modulo length of the emposition control clock cycle is greater ployed encoder.
than the modulo length.
S7-1200 Programmable controller
774
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#800C
Description
Remedy
Alarm message from drive
16#0001
-
16#003C PROFIdrive: Drive signal "Control
requested" failed
Error reaction
Remove enable.
Check the device with regard to function, connections and I/Os.
16#003D PROFIdrive: Drive has shut down
16#003E PROFIdrive: Drive at bus failed (station failure)
16#003F
16#800D
PROFIdrive: Signs of life of drive
faulty
•
Check the device with regard to
function, connections and I/Os.
•
Compare the clock parameters of
HW Config (PROFIBUS line, slave
OM for drive or encoder) and the
execution system. Tmapc and servo
must be configured with the same
clock cycle time.
The permitted following error was exceeded
16#0001
16#800E
-
•
Check the configuration of the control loop.
•
Check the direction signal of the
encoder.
•
Check the configuration of following
error monitoring.
Error at the hardware limit switch
16#0042
Illegal free travel direction with active
hardware limit switch
Remove enable.
Remove enable.
The programmed direction of movement is disabled due to the active
hardware limit switch.
Retract the axis in the opposite direction.
16#0043
Hardware limit switch polarity is reversed, axis cannot be freed
16#0044
Both hardware limit switches are
active, axis cannot be freed
16#800F
Check the mechanical configuration of
the hardware limit switch.
Error in target range
16#0045
16#0046
Target range not reached
Exit target range again
Remove enable.
Target range was not reached within
the positioning tolerance time.
•
Check the configuration of the position monitoring.
•
Check the configuration of the control loop.
The target range was exited within the
minimum dwell time.
•
Check the configuration of the position monitoring.
•
Check the configuration of the control loop.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
775
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8010
Description
Remedy
Error reaction
Position of the low SW limit switch is greater than that of the high SW limit
switch when the axis is not a modulo axis
16#0001
-
Remove enable.
Change the position of the software
limit switches.
Operating error without axis stop
ErrorID
ErrorInfo
16#8200
Description
Remedy
Axis is not enabled
16#0001
-
Enable the axis; restart the command.
16#003D
Displayed if a drive with an analog drive connection has turned off.
Enable the axis; restart the command.
16#8201
Axis has already been enabled by another "MC_Power" instance
16#0001
16#8202
-
Enable the axis with only one "MC_Power" instance.
The maximum number of simultaneous motion control commands has been exceeded (max. 200
commands for drive connection via PTO (Pulse Train Output), max. 100 commands for drive connection via PROFIdrive/analog output)
16#0001
-
Reduce the number of simultaneously active
commands; restart the command
A command is active if parameter "Busy" = TRUE
in the motion control instruction.
16#8203
Axis is currently operated in "Manual control" (axis control panel)
16#0001
16#8204
-
Exit "Manual control"; restart the command.
Axis is not homed
16#0001
16#8205
-
Home the axis with instruction "MC_Home"; restart
the command.
The axis is currently controlled by the user program (the error is only displayed in the axis control
panel)
16#0013
The axis is enabled in the user program
16#0001
-
16#8206
Disable axis with instruction "MC_Power" and
select "Manual control" again in the axis control
panel
Technology object not activated yet
16#8207
Enable the axis with instruction "MC_Power" Enable = TRUE or enable the axis in the axis control
panel.
Command rejected
16#0016
Active homing is running; another homing
method cannot be started.
Wait for active homing to finish or abort the active
homing with a motion command, for example,
"MC_Halt".
16#0018
The axis cannot be moved with a command
table while it is being actively or passively
homed.
Wait until direct or passive homing is complete.
16#0019
The axis cannot be actively or passively
homed while a command table is being processed.
Wait for command table to finish or abort the
command table with a motion command, for example, "MC_Halt".
S7-1200 Programmable controller
776
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
Description
Remedy
16#0052
The specified position exceeds the numerical
limit.
Enter a valid position value at the motion control
instruction.
16#0053
The axis is ramping up.
Wait until the axis is ready for operation.
16#0054
Actual value is invalid
To execute a "MC_Home" command, the actual
values must be valid.
Check the status of the actual values. The tag of
the technology object ."StatusSensor.State" must show the value
2 (valid).
16#8208
Difference between maximum and start/stop velocity is invalid
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
16#8209
Correct the value; restart the command.
Invalid acceleration for technology object "Axis"
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
16#0013
The axis is enabled in the user program
16#0027
The axis is currently being operated in "Manual Exit "Manual control"; restart again.
control" (axis control panel)
16#002C
The axis is not disabled.
Disable the axis; restart the command.
16#0047
The technology object is not ready for restart.
Download the project again.
16#0048
Condition for restart of the technology object is Disable the technology object.
not satisfied.
16#0026
Executing loading process in RUN mode
16#820A
Correct the value; restart the command.
It is not possible to restart the axis
16#820B
Disable the axis with the "MC_Power" instruction;
restart again.
It is not possible to execute the command table
16#820C
Wait until the loading process is complete.
No configuration available
16#0001
-
Internal error
Contact the hotline.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
777
Technology instructions
10.3 Motion control
Block parameter error
ErrorID
ErrorInfo
16#8400
Description
Remedy
Invalid value at parameter "Position" of the motion control instruction
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
Value is outside the number range (less than
1E+12)
16#8401
Correct the value; restart the command.
Invalid value at parameter "Distance" of the motion control instruction
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
Value is outside the number range (less than
1E+12)
16#8402
Correct the value; restart the command.
Invalid value at parameter "Velocity" of the motion control instruction
16#0002
Value is not a valid number
16#0008
Value is greater than the configured maximum
velocity
16#0009
Value is less than the configured start/stop
velocity
16#0024
Value is less than 0
16#0011
The selection value is invalid
16#8403
Correct the value; restart the command.
Invalid value at parameter "Direction" of the motion control instruction
16#8404
Correct the selection value; restart the command.
Invalid value at parameter "Mode" of the motion control instruction
16#0011
The selection value is invalid
Correct the selection value; restart the command.
16#0015
Active/passive homing is not configured
Correct the configuration and download it to the
controller; enable the axis and restart the command.
16#0017
The direction reversal is activated at the hardware limit switch, despite the fact that the
hardware limit switches are disabled
•
Activate the HW limit switch using the tag
.PositionLimitsHW.Active =
TRUE, restart the command.
•
Correct the configuration and download it to
the controller; enable the axis and restart the
command.
16#0055
Invalid mode at incremental encoder
Start a homing process for an incremental encoder using parameter "Mode" = 0, 1, 2, 3.
16#0056
Invalid mode at absolute encoder
Passive and active homing ("Mode" = 2, 3) are not
possible for an absolute value encoder.
Start a homing process for an absolute encoder
using parameter "Mode" = 0, 1.
16#8405
Invalid value at parameter "StopMode" of the motion control instruction
16#0011
The selection value is invalid
Correct the selection value; enable the axis again.
S7-1200 Programmable controller
778
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8406
Description
Remedy
Simultaneous forward and backward jogging is not allowed
16#0001
16#8407
-
Take steps to ensure that parameters "JogForward" and "JogBackward" do not have signal
status TRUE simultaneously; restart the command.
Switching to another axis with instruction "MC_Power" is only permitted after disabling the active
axis.
16#0001
16#8408
-
Disable the active axis; it is then possible to switch
to the other axis and enable it.
Invalid value at parameter "Axis" of the motion control instruction
16#001A
The specified value does not match the required technology object version
16#001B
The specified value does not match the required technology object type
16#001C
The specified value is not a motion control
technology data block
16#8409
Correct the value; restart the command.
Invalid value at parameter "CommandTable" of the motion control instruction
16#001A
The specified value does not match the required technology object version
16#001B
The specified value does not match the required technology object type
16#001C
The specified value is not a motion control
technology data block
16#840A
Correct the value; restart the command.
Invalid value at parameter "StartStep" of the motion control instruction
16#000A
Value is less than or equal to 0.
16#001D
The start step is greater than the end step
16#001E
Value is greater than 32
16#840B
Correct the value; restart the command.
Invalid value at parameter "EndStep" of the motion control instruction
16#000A
Value is less than or equal to 0.
16#001E
Value is greater than 32
16#840C
Correct the value; restart the command.
Invalid value at parameter "RampUpTime" of the motion control instruction
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
16#840D
Correct the value; restart the command.
Invalid value at parameter "RampDownTime" of the motion control instruction
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
16#840E
Correct the value; restart the command.
Invalid value at parameter "EmergencyRampTime" of the motion control instruction
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
16#840F
Correct the value; restart the command.
Invalid value at parameter "JerkTime" of the motion control instruction
16#0002
Value is not a valid number
16#000A
Value is less than or equal to 0.
Correct the value; restart the command.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
779
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8410
Description
Remedy
Invalid value at parameter "Parameter" of the motion control instruction
16#0002
Value is not a valid number
Correct the value; restart the command.
16#000B
Address is invalid
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
16#0028
Data type of VARIANT pointer "Parameter"
and "Value" do not match.
Use a suitable data type; restart command.
16#0029
VARIANT pointer "Parameter" does not point
to a data block of the technology object.
Correct the VARIANT pointer; restart the command.
16#002A
The value at the VARIANT pointer "Parameter" Correct the VARIANT pointer; restart the comcannot be read.
mand.
16#002B
The value at the VARIANT pointer "Parameter" Correct the VARIANT pointer or value; restart the
cannot be written.
command.
16#002C
The axis is not disabled.
16#8411
Disable the axis; restart the command.
Invalid value at parameter "Value" of the motion control instruction
16#0002
Value is not a valid number
Correct the value; restart the command.
Configuration error of the axis
ErrorID
ErrorInfo
16#8600
Description
Remedy
Parameter assignment of pulse generator (PTO is invalid
16#000B
The address is invalid
16#0014
The selected hardware is used by another
application
16#8601
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Parameter assignment of the high-speed counter (HSC) is invalid
16#000B
The address is invalid
16#0014
The selected hardware is used by another
application
16#8602
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid parameter assignment of "Enable output"
16#000B
The address is invalid
16#000B
The address is invalid
16#8603
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid parameter assignment of "Ready input"
16#8604
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid "Pulses per motor revolution" value
16#000A
Value is less than or equal to zero
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
S7-1200 Programmable controller
780
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8605
Description
Remedy
Invalid "Distance per revolution" value
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#000A
Value is less than or equal to zero
16#0030
Value has an incorrect number format or is
outside the valid number range
16#8606
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid "Start/stop velocity" value
16#0002
Value is not a valid number
16#0003
Value is higher than the high hardware limit
16#0004
Value is lower than the low hardware limit
16#0007
The start/stop velocity is greater than the maximum velocity
16#8607
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid "maximum velocity" value
16#0002
Value is not a valid number
16#0003
Value is higher than the high hardware limit
16#0004
Value is lower than the low hardware limit
16#0030
Value has an incorrect number format or is
outside the valid number range
16#8608
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid "Acceleration" value
16#0002
Value is not a valid number
16#0003
Value is higher than the high hardware limit
16#0004
Value is lower than the low hardware limit
16#0030
Value has an incorrect number format or is
outside the valid number range
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
781
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8609
Description
Remedy
Invalid "Deceleration" value
16#0002
Value is not a valid number
16#0003
Value is higher than the high hardware limit
16#0004
Value is lower than the low hardware limit
16#0030
Value has an incorrect number format or is
outside the valid number range
16#860A
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid "Emergency stop deceleration" value
16#0002
Value is not a valid number
16#0003
Value is higher than the high hardware limit
16#0004
Value is lower than the low hardware limit
16#0030
Value has an incorrect number format or is
outside the valid number range
16#860B
Value for position of the low SW limit switch is invalid
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
Value is outside the number range (less than
1E+12)
16#0030
The position value of the low software limit
switch is greater than that of the high software
limit switch
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
782
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#860C
Description
Remedy
Value for position of the high SW limit switch is invalid
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
16#0030
16#860D
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
Value is outside the number range (less than
1E+12)
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid address of the low HW limit switch
16#000B
Invalid address
16#000C
The address of the falling edge is invalid
16#000D
The address of the rising edge is invalid
16#860E
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid address of the high HW limit switch
16#000B
Invalid address
16#000C
The address of the falling edge is invalid
16#000D
The address of the rising edge is invalid
16#860F
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid "home position offset" value
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
16#0030
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
Value is outside the number range (less than
1E+12)
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
783
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8610
Description
Remedy
Invalid "approach velocity" value
16#0002
Value is not a valid number
16#0008
The velocity is greater than the maximum
velocity
16#0009
16#0030
16#8611
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
The velocity is less than the start/stop velocity
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
Invalid "Homing velocity" value
16#0002
Value is not a valid number
16#0008
The velocity is greater than the maximum
velocity
16#0009
The velocity is less than the start/stop velocity
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
16#8612
Invalid address of the homing switch
16#000B
Invalid address
16#000C
The address of the falling edge is invalid
16#000D
The address of the rising edge is invalid
16#8613
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
During active homing, direction reversal at the hardware limit switch is activated although the hardware limit switches are not configured
16#0001
-
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
784
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8614
Description
Remedy
Invalid "Jerk" value
16#0002
Value is not a valid number
16#001F
Value is greater than the maximum jerk
16#0020
Value is less than the minimum jerk
16#0030
Value has an incorrect number format or is
outside the valid number range
16#8615
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Value for "Unit of measurement" is invalid
16#0011
16#8616
The selection value is invalid
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Address of homing switch is invalid (passive homing as of V4)
16#0011
16#0030
16#8617
The selection value is invalid
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Value of tag .Sensor.Sensor[1].ActiveHoming.Mode is invalid
16#0011
The selection value is invalid
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
(Valid value: 2 = Homing via digital input)
16#8618
Value of tag .Sensor.Sensor[1].PassiveHoming.Mode is invalid
16#0011
The selection value is invalid
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
(Valid value: 2 = Homing via digital input)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
785
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8619
Description
Remedy
Value of tag .Actor.Type is invalid
16#0011
The selection value is invalid
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
(Valid value: 2 = Connection via pulse interface)
16#861A
Value for "Permitted direction of rotation" is invalid
16#0011
The selection value is invalid
16#002D
"Both directions" not allowed when direction
output is deactivated
16#861B
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Faulty load gear factors
16#0031
Value is invalid.
16#0031
Value is invalid.
16#861C
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Illegal combination of data for homing with incremental encoder
16#861D
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The set encoder mounting type is invalid. Invalid value in .Sensor.Sensor[1].MountingMode
16#0011
16#861E
The selection value is invalid
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The configuration of the measuring wheel circumference of the encoder is invalid. Invalid value in
.Sensor.Sensor[1].Parameter.DistancePerRevolution
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
786
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#861F
Description
Remedy
The configuration for the resolution of the linear encoder is faulty. Invalid value in .Sensor.Sensor[1].Parameter.Resolution
16#0030
16#8620
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The set fine resolution for Gn_XIST1 is invalid. Invalid value in .Sensor.Sensor[1].Parameter.FineResolutionXist1
16#0030
16#8621
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The set fine resolution for Gn_XIST1 in .Sensor.Sensor[1].Parameter.FineResolutionXist1 is not consistent with the setting in
PROFIdrive parameter P979
16#0030
16#8622
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid value for the configuration date .Actor.Interface.AddressIn or .Actor.Interface.AddressOut
16#0011
16#8623
The selection value is invalid
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
The value set in the tag .Sensor.Sensor[1].Type is invalid.
16#0011
16#8624
The selection value is invalid
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
The set encoder system is invalid. Invalid value in .Sensor.Sensor[1].System
16#0011
The selection value is invalid
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
787
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8625
Description
Remedy
Parameter of position monitoring is faulty. Invalid value in .PositioningMonitoring.MinDwellTime
16#0030
16#8626
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Parameter of position monitoring is faulty. Invalid value in .PositioningMonitoring.Window
16#0030
16#8627
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The configuration of the PROFIdrive interface of the actual value is faulty. Invalid value in .Sensor.Sensor[1].Interface.AddressIn or .Sensor.Sensor[1].Interface.AddressOut
16#0011
The selection value is invalid
16#0030
Value has an incorrect number format or is
outside the valid number range
16#8628
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Faulty controller factors
16#8629
The value for the gain or the precontrol of the
control loop is faulty.
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary. (.PositionControl.Kv, .PositionControl.Kpc)
Limit for standstill signal is faulty. Invalid value in .StandStillSignal.VelocityThreshold
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
788
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#862A
Description
Remedy
Parameter of position monitoring is faulty. Invalid value in .PositioningMonitoring.ToleranceTime
16#0030
16#862B
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Inconsistent PROFIBUS parameterization; the sum of Ti and To is greater than one DP cycle
16#0030
16#862C
Value has an incorrect number format or is
outside the valid number range
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Parameter of standstill monitoring is faulty. Invalid value in .StandStillSignal.MinDwellTime
16#0030
16#862D
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Parameter of following error monitoring is faulty. Invalid value in .FollowingError.MinValue
16#0030
16#862E
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid value for the configuration date .Modulo.Length
16#0030
16#862F
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid value for the configuration date .Modulo.StartValue
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
789
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8630
Description
Remedy
Invalid value for the configuration date .Actor.DriveParameter.ReferenceSpeed
16#0030
16#8631
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The set fine resolution for Gn_XIST2 is invalid. Invalid value in .Sensor.Sensor[1].Parameter.FineResolutionXist2
16#0030
16#8632
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The number of determinable encoder revolutions is invalid. Invalid value in .Sensor.Sensor[1].Parameter.DeterminableRevolutions
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
16#8633
The specified approach direction of the homing switch for passive homing is invalid. Invalid value in
.Sensor.Sensor[1].PassiveHoming.Direction
16#8634
Parameter of the following error monitoring is faulty. Invalid value in .FollowingError.MaxValue
16#0030
16#8635
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Parameter of the following error monitoring is faulty. Invalid value in .FollowingError.MinVelocity
16#0030
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
S7-1200 Programmable controller
790
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#8636
Description
Remedy
Controller factor is incorrect. Invalid value of the precontrol factor .PositionControl.Kpc
16#0030
16#8637
Value has an incorrect number format or is
outside the valid number range
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
Invalid value for the configuration date .Sensor.Sensor[1].Interface.Type
16#0011
The selection value is invalid
16#0011
The selection value is invalid
16#0049
Configuration error at device
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
16#004A
The technology needs a smaller servo clock.
Internal system error.
16#8638
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Invalid value for the configuration date .Sensor.Sensor[1].Interface.HSC
16#8639
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
Error at the drive
Check the project for consistency and reload it into
the controller.
16#004B
Device driver not initialized during ramp-up.
To enable a technology object, the actuator driver
must be initialized.
Execute the command again later.
16#863A
Communication to the drive is faulty
16#004C
16#004D
16#004E
Configuration error at device
The device driver needs a smaller servo clock.
•
Connect a suitable device.
•
Check the device (I/Os).
•
Compare the configuration of HW Config and
the technology object.
•
Connect a suitable device.
•
Check the device (I/Os).
•
Compare the configuration of HW Config and
the technology object.
Error in internal communication with the device Check the project for consistency and reload it into
the controller.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
791
Technology instructions
10.3 Motion control
ErrorID
ErrorInfo
16#863B
Description
Remedy
Error at encoder
16#0049
Configuration error at device
Download error-free configuration to the controller;
enable the axis again with instruction
"MC_Power".
16#004A
The technology needs a smaller servo clock.
Internal system error.
Check the project for consistency and reload it into
the controller.
16#004B
Device driver not initialized during ramp-up.
To enable a technology object, the actuator driver
must be initialized.
Execute the command again later.
16#863C
Communication with encoder is faulty
16#004C
16#004D
Configuration error at device
The device driver needs a smaller servo clock.
•
Connect a suitable device.
•
Check the device (I/Os).
•
Compare the configuration of HW Config and
the technology object.
•
Connect a suitable device.
•
Check the device (I/Os).
•
Compare the configuration of HW Config and
the technology object.
16#004E
Error in internal communication with the device Check the project for consistency and reload it into
the controller.
16#0030
Value has an incorrect number format or is
outside the valid number range
16#863D
Communication to the device (drive or encoder) is faulty
16#0055
16#0056
16#0057
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online;
acknowledge error with instruction "MC_Reset"
and restart the command, if necessary.
The requested logical address is invalid.
•
The requested logical output address is invalid. •
The requested logical output address is invalid. •
•
16#863E
Connect a suitable device.
Check the device (I/Os).
Check the topological configuration in HW
Config.
Compare the configuration of HW Config and
the technology object.
Value of tag "ControlPanel.Input.TimeOut" is invalid (axis control panel)
16#0030
Value has an incorrect number format or is
outside the valid number range
Correct the value in the tags of the technology
object .ControlPanel.Input.TimeOut.
The value is specified in milliseconds (ms).
16#863F
Invalid value for the configuration date .Actor.DriveParameter.MaxSpeed
16#0030
Value has an incorrect number format or is
outside the valid number range
Correct the reference value in the drive and in the
configuration of the technology object to Actuator.MaxSpeed/2.
With analog drive connection, correct the reference value in the drive and in the configuration of
the technology object to Actuator.MaxSpeed/1.17.
S7-1200 Programmable controller
792
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Data adaptation errors
ErrorID
16#8640
ErrorInfo
Description
Remedy
Error reaction
Errors when adapting actuator configuration
16#0030 Value has the wrong numerical format or is outside the valid number
range.
Restart
Adaptation Error
16#0059 The device is not assigned to any
SINAMICS drive unit or does not
support the services necessary for
adaptation.
Restart
Adaptation Error
16#005A Adaptation was cancelled because of
the lack of resources.
Restart
Adaptation Error
16#005B Adaptation is possible only if the
device was wired directly to an IO
area.
Restart
Adaptation Error
16#005C Maximum speed (p1082): Parameter Restart
does not exist or its value cannot be
read or is outside the permitted limits.
Reading the parameters was cancelled because of an error indicated
by the hardware.
Adaptation Error
16#005D Maximum torque/force (p1520): PaRestart
rameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
16#005E Maximum torque/force (p1521): PaRestart
rameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
16#005F Fine resolution torque/force limit
Restart
(p1544): Parameter does not exist or
its value cannot be read or is outside
the permitted limits. Reading the
parameters was cancelled because
of an error indicated by the hardware.
Adaptation Error
16#0060 Basic speed/rated speed (p2000):
Restart
Parameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
16#0061 Rated torque/rated force (p2003):
Restart
Parameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
793
Technology instructions
10.3 Motion control
ErrorID
16#8041
ErrorInfo
Description
Remedy
Error reaction
Errors when adapting the encoder configuration
16#0030 Value has the wrong numerical format or is outside the valid number
range.
Restart
Adaptation Error
16#005A Adaptation was cancelled because of Restart
a lack of resources.
Adaptation Error
16#005B Adaptation is possible only if the
device was wired directly to an IO
area.
Restart
Adaptation Error
16#0059 The device is not assigned to any
SINAMICS drive unit or does not
support the services necessary for
adaptation.
Restart
Adaptation Error
16#0062 Encoder System (r0979[1/11].0): A
Restart
parameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
16#0063 Encoder resolution (r0979[2/12]): A
Restart
parameter does not exist or its value
cannot be read or is outside the permitted limits. Reading the parameters
was cancelled because of an error
indicated by the hardware.
Adaptation Error
16#0064 Encoder resolution Gx_XIST1
(r0979[3/13]): A parameter does not
exist or its value cannot be read or is
outside the permitted limits. Reading
the parameters was cancelled because of an error indicated by the
hardware.
Restart
Adaptation Error
16#0065 Encoder resolution Gx_XIST2
(r0979[4/14]): A parameter does not
exist or its value cannot be read or is
outside the permitted limits. Reading
the parameters was cancelled because of an error indicated by the
hardware.
Restart
Adaptation Error
16#0066 Number of resolvable encoder revolu- Restart
tions (r0979[5/15]): A parameter does
not exist or its value cannot be read
or is outside the permitted limits.
Reading the parameters was cancelled because of an error indicated
by the hardware.
Adaptation Error
S7-1200 Programmable controller
794
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
ErrorID
16#8642
ErrorInfo
Description
Remedy
Configuration is adapted internally
16#0067 1: Impermissible value for AcReset
tor.MaxSpeed (Actor.MaxSpeed
larger than 2*Actor.ReferenceSpeed);
Remedy: in drive, set P2000 = P1082
for example.
16#8643
16#8644
16#8645
Error reaction
Configuration
error
Inconsistency between TO and drive configuration
16#0068 The configured telegram type is not
Reset
compatible with the device’s telegram
type (P922 or P2079).
Configuration
error
16#0069 The torque resolution is not compatible.
Reset
Configuration
error
16#006A The elementary period time of the
master application cycle is not identical with that of the servo clock.
Reset
Configuration
error
16#006B The processing clock of the technology object is not identical with the
drive’s application cycle.
Reset
Configuration
error
16#006C In the drive, a function module with
linear motor is set.
Reset
Configuration
error
Inconsistency between TO and encoder configuration
16#0068 The configured telegram type is not
Reset
compatible with the device’s telegram
type (P922 or P2079).
Configuration
error
16#006A The elementary period time of the
master application cycle is not identical with that of the servo clock.
Reset
Configuration
error
16#006B The processing clock of the technology object is not identical with the
drive’s application cycle.
Reset
Configuration
error
16#006D The encoder at the drive is not an
absolute value encoder (P979).
Reset
Configuration
error
Maximum velocity cannot be attained with the drive and axis parameters that were set
16#0001 General
Reset
Configuration
error
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
795
Technology instructions
10.3 Motion control
Configuration error of the command table
ErrorID
ErrorInfo
16#8700
Description
Remedy
Value for "Command type" in the command table is invalid
16#0001
16#8701
-
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online and restart
the command, if necessary.
Value for "Position / travel path" in the command table is invalid
16#0002
Value is not a valid number
16#0005
Value is outside the number range (greater
than 1E+12)
16#0006
Value is outside the number range (less than
1E+12)
16#8702
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online and restart
the command, if necessary.
Value for "Velocity" in the command table is invalid
16#0002
Value is not a valid number
16#0008
Value is greater than the configured maximum
velocity
16#0009
Value is less than the configured start/stop
velocity
16#8703
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online and restart
the command, if necessary.
Value for "Duration" in the command table is invalid
16#0002
Value is not a valid number
16#0021
Value is greater than 64800 s
16#0022
Value is less than 0.001 s
16#8704
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online and restart
the command, if necessary.
Value for "Next step" in the command table is invalid
16#0011
The selection value is invalid
16#0023
The command transition is not permitted for
this command
•
Download error-free configuration to the controller; enable the axis again with instruction
"MC_Power".
•
Correct the incorrect value online and restart
the command, if necessary.
S7-1200 Programmable controller
796
System Manual, V4.2, 09/2016, A5E02486680-AK
Technology instructions
10.3 Motion control
Internal errors
ErrorID
ErrorInfo
16#8FFF
Description
Remedy
Internal error
16#F0**
-
POWER OFF and POWER ON the CPU
If this does not work, contact Customer Support.
Have the following information ready:
•
ErrorID
•
ErrorInfo
•
Diagnostic buffer entries
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
797
Technology instructions
10.3 Motion control
S7-1200 Programmable controller
798
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11
The S7-1200 offers several types of communication between CPUs and programming
devices, HMIs, and other CPUs.
WARNING
If an attacker can physically access your networks, the attacker can possibly read and write
data.
The TIA Portal, the CPU, and HMIs (except HMIs using GET/PUT) use secure
communication that protects against replay and "man-in-the-middle" attacks. Once
communication is enabled, the exchange of signed messages takes place in clear text
which allows an attacker to read data, but protects against unauthorized writing of data.
The TIA Portal, not the communication process, encrypts the data of know-how protected
blocks.
All other forms of communication (I/O exchange through PROFIBUS, PROFINET, AS-i, or
other I/O bus, GET/PUT, T-Block, and communication modules (CM)) have no security
features. You must protect these forms of communication by limiting physical access. If an
attacker can physically access your networks utilizing these forms of communication, the
attacker can possibly read and write data.
For security information and recommendations, please see our "Operational Guidelines for
Industrial Security" (http://www.industry.siemens.com/topics/global/en/industrialsecurity/Documents/operational_guidelines_industrial_security_en.pdf) on the Siemens
Service and Support site.
PROFINET
PROFINET is used for exchanging data through the user program with other
communications partners through Ethernet:
● In the S7-1200, PROFINET supports 16 IO devices with a maximum of 256 submodules,
and PROFIBUS allows 3 independent PROFIBUS DP Masters, supporting 32 slaves per
DP master, with a maximum of 512 modules per DP master.
● S7 communication
● User Datagram Protocol (UDP) protocol
● ISO on TCP (RFC 1006)
● Transport Control Protocol (TCP)
PROFINET IO controller
As an IO controller using PROFINET IO, the CPU communicates with up to 16 PN devices
on the local PN network or through a PN/PN coupler (link). Refer to PROFIBUS and
PROFINET International, PI (www.us.profinet.com) for more information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
799
Communication
PROFIBUS
PROFIBUS is used for exchanging data through the user program with other
communications partners through the PROFIBUS network:
● With CM 1242-5, the CPU operates as a PROFIBUS DP slave.
● With CM 1243-5, the CPU operates as a PROFIBUS DP master class1.
● PROFIBUS DP Slaves, PROFIBUS DP Masters, and AS-i (the 3 left-side communication
modules) and PROFINET are separate communications networks that do not limit each
other.
AS-i
The S7-1200 CM 1243-2 AS-i Master allows the attachment of an AS-i network to an S71200 CPU.
CPU-to-CPU S7 communication
You can create a communication connection to a partner station and use the GET and PUT
instructions to communicate with S7 CPUs.
TeleService communication
In TeleService via GPRS, an engineering station on which STEP 7 is installed communicates
via the GSM network and the Internet with a SIMATIC S7-1200 station with a CP 1242-7.
The connection runs via a telecontrol server that serves as an intermediary and is connected
to the Internet.
IO-Link
The S7-1200 SM 1278 4xIO-Link Master enables IO-Link devices to connect to an S7-1200
CPU.
S7-1200 Programmable controller
800
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.1 Asynchronous communication connections
11.1
Asynchronous communication connections
Overview of communication services
The CPU supports the following communication services:
Communication service
Using PROFIBUS DP
CM 1243-5
DP master
module
CM 1242-5
DP slave
module
Using
Ethernet
PG communication
Commissioning, testing, diagnostics
Yes
No
Yes
HMI communication
Operator control and monitoring
Yes
No
Yes
S7 communication
Data exchange using configured
connections
Yes
No
Yes
Routing of PG functions
For example, testing and diagnostics beyond network boundaries
No
No
No
PROFIBUS DP
Data exchange between master
and slave
Yes
Yes
No
PROFINET IO
Data exchange between I/O controllers and I/O devices
No
No
Yes
Web server
Diagnostics
No
No
Yes
SNMP 1
Standard protocol for network
diagnostics and parameterization
No
No
Yes
S7 routing
Using routing tables, communication partners can communicate
with each device even though the
devices are on different S7 subnets.
No
No
Yes
Open communication
over TCP/IP
Data exchange over Industrial
Ethernet with TCP/IP protocol (with
loadable FBs)
No
No
Yes
Open communication
over ISO on TCP
Data exchange over Industrial
Ethernet with ISO on TCP protocol
(with loadable FBs)
No
No
Yes
Open communication
over UDP
Data exchange over Industrial
Ethernet with UDP protocol (with
loadable FBs)
No
No
Yes
(Simple Network Management Protocol)
1
Functionality
The CPU supports SNMP V1 without TRAPs.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
801
Communication
11.1 Asynchronous communication connections
Available connections
The CPU supports the following number of maximum simultaneous, asynchronous
communication connections for PROFINET and PROFIBUS. The maximum number of
connection resources allocated to each category are fixed; you cannot change these values.
However, you can configure the 6 "Free available connections" to increase the number of
any category as required by your application.
Note
The total number of S7-1200 communication connections does not increase when you add
CM/CP modules.
Based upon the allocated connection resources, the following number of connections per
device are available:
Maximum
number of
connection
resources
Programming
terminal (PG)
Human Machine
Interface (HMI)
GET/PUT
client/server
Open User
Communications
Web browser
3
(guaranteed to
support
1 PG device)
12
(guaranteed to
support
4 HMI devices)
8
8
30
(guaranteed to
support
3 web browsers)
For an example, a PG has 3 available connection resources. Depending on the current PG
functions in use, the PG might actually use 1, 2, or 3 of its available connection resources. In
the S7-1200, you are always guaranteed at least 1 PG; however, no more than 1 PG is
allowed.
Another example is the number of HMIs, as shown in the figure below. HMIs have 12
available connection resources. Depending on what HMI type or model that you have and
the HMI functions that you use, each HMI might actually use 1, 2, or 3 of its available
connection resources. Given the number of available connection resources being used, it
may be possible to use more than 4 HMIs at one time. However, you are always guaranteed
at least 4 HMIs. An HMI can use its available connection resources (1 each for a total of 3)
for the following functions:
● Reading
● Writing
● Alarming plus diagnostics
S7-1200 Programmable controller
802
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.1 Asynchronous communication connections
This is only an example. The actual number of connections used can vary by HMI type and
version.
Example
Connection
resources
used
HMI 1
HMI 2
HMI 3
HMI 4
HMI 5
2
2
2
3
3
Total connection
resources
available
12
Note
Web server (HTTP) connections: The CPU provides connections for multiple web browsers.
The number of browsers that the CPU can simultaneously support depends upon how many
connections a given web browser requests/utilizes.
Note
The Open User Communications, S7 connection, HMI, programming device, and Web server
(HTTP) communication connections may utilize multiple connection resources based upon
the features currently being used.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
803
Communication
11.2 PROFINET
11.2
PROFINET
The CPU can communicate with other CPUs, with programming devices, with HMI devices,
and with non-Siemens devices using standard TCP communications protocols.
Programming device connected to the
CPU
HMI connected to the CPU
A CPU connected to another CPU
S7-1200 Programmable controller
804
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Ethernet switching
The CPU 1211C, 1212C, and 1214C have a single Ethernet port and do not include a
integrated Ethernet Switch. A direct connection between a programming device or HMI and a
CPU does not require an Ethernet switch. However, a network with more than two CPUs or
HMI devices requires an Ethernet switch.
① CPU 1215C
② CSM1277 Ethernet switch
The CPU 1215C and the CPU 1217C have a built-in 2-port Ethernet switch. You can have a
network with a CPU 1215C and two other S7-1200 CPUs. You can also use the rackmounted CSM1277 4-port Ethernet switch for connecting multiple CPUs and HMI devices.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
805
Communication
11.2 PROFINET
11.2.1
Creating a network connection
Use the "Network view" of Device configuration to create the network connections between
the devices in your project. After creating the network connection, use the "Properties" tab of
the inspector window to configure the parameters of the network.
Table 11- 1
Creating a network connection
Action
Result
Select "Network view" to display the
devices to be connected.
Select the port on one device and
drag the connection to the port on
the second device.
Release the mouse button to create
the network connection.
S7-1200 Programmable controller
806
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.2
Configuring the Local/Partner connection path
A Local / Partner (remote) connection defines a logical assignment of two communication
partners to establish communication services. A connection defines the following:
● Communication partners involved (One active, one passive)
● Type of connection (for example, a PLC, HMI, or device connection)
● Connection path
Communication partners execute the instructions to set up and establish the communication
connection. You use parameters to specify the active and passive communication end point
partners. After the connection is set up and established, it is automatically maintained and
monitored by the CPU.
If the connection is terminated (for example, due to a line break), the active partner attempts
to re-establish the configured connection. You do not have to execute the communication
instruction again.
Connection paths
After inserting a TSEND_C, TRCV_C or TCON instruction into the user program, the
inspector window displays the properties of the connection whenever you have selected any
part of the instruction. Specify the communication parameters in the "Configuration" tab of
the "Properties" for the communication instruction.
Table 11- 2
Configuring the connection path (using the properties of the instruction)
TCP, ISO-on-TCP, and UDP
Connection properties
For the TCP, ISO-on-TCP, and UDP Ethernet
protocols, use the "Properties" of the instruction
(TSEND_C, TRCV_C, or TCON) to configure the
"Local/Partner" connections.
The illustration shows the "Connection properties" of the "Configuration tab" for an ISO-onTCP connection.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
807
Communication
11.2 PROFINET
Note
When you configure the connection properties for one CPU, STEP 7 allows you either to
select a specific connection DB in the partner CPU (if one exists), or to create the connection
DB for the partner CPU. The partner CPU must already have been created for the project
and cannot be an "unspecified" CPU.
You must still insert a TSEND_C, TRCV_C or TCON instruction into the user program of the
partner CPU. When you insert the instruction, select the connection DB that was created by
the configuration.
Table 11- 3
Configuring the connection path for S7 communication (Device configuration)
S7 communication (GET and PUT)
Connection properties
For S7 communication, use the "Devices & networks" editor of the network to configure the
Local/Partner connections. You can click the
"Highlighted: Connection" button to access the
"Properties".
The "General" tab provides several properties:
•
"General" (shown)
•
"Local ID"
•
"Special connection properties"
•
"Address details" (shown)
Refer to "Protocols" (Page 825) in the "PROFINET" section or to "Creating an S7
connection" (Page 991) in the "S7 communication" section for more information and a list of
available communication instructions.
S7-1200 Programmable controller
808
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 4
Parameters for the multiple CPU connection
Parameter
Definition
Address
General
Address details
Assigned IP addresses
End point
Name assigned to the partner (receiving) CPU
Interface
Name assigned to the interfaces
Subnet
Name assigned to the subnets
Interface type
S7 communication only: Type of interface
Connection type
Type of Ethernet protocol
Connection ID
ID number
Connection data
Local and Partner CPU data storage location
Establish active connection
Radio button to select Local or Partner CPU as the active connection
End point
S7 communication only: Name assigned to the partner (receiving) CPU
Rack/slot
S7 communication only: Rack and slot location
Connection resource
S7 communication only: Component of the TSAP used when configuring an
Port (decimal):
TCP and UPD: Partner CPU port in decimal format
TSAP and Subnet ID:
ISO on TCP (RFC 1006) and S7 communication: Local and partner CPU
TSAPs in ASCII and hexadecimal formats
1
1
S7 connection with an S7-300 or S7-400 CPU
When configuring a connection with an S7-1200 CPU for ISO-on-TCP, use only ASCII characters in the TSAP extension
for the passive communication partners.
Transport Service Access Points (TSAPs)
Using TSAPs, ISO on TCP protocol and S7 communication allows multiple connections to a
single IP address. TSAPs uniquely identify these communication end point connections to an
IP address.
In the "Address Details" section of the Connection Parameters dialog, you define the TSAPs
to be used. The TSAP of a connection in the CPU is entered in the "Local TSAP" field. The
TSAP assigned for the connection in your partner CPU is entered under the "Partner TSAP"
field.
Port Numbers
With TCP and UDP protocols, the connection parameter configuration of the Local (active)
connection CPU must specify the remote IP address and port number of the Partner
(passive) connection CPU.
In the "Address Details" section of the Connection Parameters dialog, you define the ports to
be used. The port of a connection in the CPU is entered in the "Local Port" field. The port
assigned for the connection in your partner CPU is entered under the "Partner Port" field.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
809
Communication
11.2 PROFINET
11.2.3
Assigning Internet Protocol (IP) addresses
11.2.3.1
Assigning IP addresses to programming and network devices
If your programming device is using an on-board adapter card connected to your plant LAN
(and possibly the world-wide web), both the programming device and the CPU must exist on
the same subnet. You assign the subnet as a combination of the IP address and subnet
mask for the device. Please see your local network administrator for help.
The Network ID is the first part of the IP address (first three octets) (for example,
211.154.184.16) that determines what IP network you are on. The subnet mask normally has
a value of 255.255.255.0; however, since your computer is on a plant LAN, the subnet mask
may have various values (for example, 255.255.254.0) in order to set up unique subnets.
The subnet mask, when combined with the device IP address in a logical AND operation,
defines the boundaries of an IP subnet.
Note
In a World Wide Web scenario, where your programming devices, network devices, and IP
routers communicate with the world, you must assign unique IP addresses to avoid conflict
with other network users. Contact your company IT department personnel, who are familiar
with your plant networks, for assignment of your IP addresses.
WARNING
Unauthorized access to the CPU through the Web server
Unauthorized access to the CPU or changing PLC variables to invalid values could disrupt
process operation and could result in death, severe personal injury and/or property
damage.
Enabling the Web server allows authorized users to perform operating mode changes,
writes to PLC data, and firmware updates, Siemens recommends that you observe the
following security practices:
• Enable access to the Web server only with the HTTPS protocol.
• Password-protect Web server user IDs (Page 1005) with a strong password. Strong
passwords are at least ten characters in length, mix letters, numbers, and special
characters, are not words that can be found in a dictionary, and are not names or
identifiers that can be derived from personal information. Keep the password secret and
change it frequently.
• Do not extend the default minimum privileges of the "Everybody" user.
• Perform error-checking and range-checking on your variables in your program logic
because Web page users can change PLC variables to invalid values.
Note
A secondary network adapter card is useful when you do not want your CPU on your
company LAN. During initial testing or commissioning tests, this arrangement is particularly
useful.
S7-1200 Programmable controller
810
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Assigning or checking the IP address of your programming device using "My Network Places" (on
your desktop)
If you are using Windows 7, you can assign or check your programming device's IP address
with the following menu selections:
● "Start"
● "Control Panel"
● "Network and Sharing Center"
● "Local Area Connection" for the network adapter connected to your CPU
● "Properties"
● In the "Local Area Connection Properties" dialog, in the "This connection uses the
following items:" field:
– Scroll down to "Internet Protocol Version 4 (TCP/IPv4)"
– Click "Internet Protocol Version 4 (TCP/IPv4)".
– Click the "Properties" button.
– Select "Obtain an IP address automatically (DCP)" or "Use the following IP address"
(to enter a static IP address).
● If you have the "Obtain an IP address automatically" selected you may want to change
the selection to "Use the following IP address" to connect to the S7-1200 CPU:
– Select an IP address on the same subnet as the CPU (192.168.0.1).
– Set the IP address to an address with the same Network ID (for example,
192.168.0.200).
– Select a subnet mask of 255.255.255.0.
– Leave the default gateway blank.
– This will allow you to connect to the CPU.
Note
The Network Interface Card and the CPU must be on the same subnet to allow STEP 7 to
find and communicate with the CPU.
Consult your IT personnel to help you set up a network configuration to allow you to connect
to the S7-1200 CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
811
Communication
11.2 PROFINET
11.2.3.2
Checking the IP address of your programming device
You can check the MAC and IP addresses of your programming device with the following
menu selections:
1. In the "Project tree", expand "Online access".
2. Right-click the required network, and select "Properties".
3. In the network dialog, expand "Configurations", and select "Industrial Ethernet".
The MAC and IP addresses of the programming device are displayed.
S7-1200 Programmable controller
812
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.3.3
Assigning an IP address to a CPU online
You can assign an IP address to a network device online. This is particularly useful in an
initial device configuration.
1. In the "Project tree," verify that
no IP address is assigned to the
CPU, with the following menu
selections:
• "Online access"
•
• "Update accessible devices"
NOTE: If STEP 7 displays a MAC
address instead of an IP address,
then no IP address has been assigned.
2. Under the required accessible
device, double-click "Online &
diagnostics".
3. In the "Online & diagnostics"
dialog, make the following menu
selections:
• "Functions"
• "Assign IP address"
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
813
Communication
11.2 PROFINET
4. In the "IP address" field, enter
your new IP address, and click the
"Assign IP address" button.
5. In the "Project tree," verify that
your new IP address has been
assigned to the CPU, with the
following menu selections:
• "Online access"
•
• "Update accessible devices"
11.2.3.4
Configuring an IP address for a CPU in your project
Configuring the PROFINET interface
To configure parameters for the PROFINET interface, select the green PROFINET box on
the CPU. The "Properties" tab in the inspector window displays the PROFINET port.
①
PROFINET port
S7-1200 Programmable controller
814
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Configuring the IP address
Ethernet (MAC) address: In a PROFINET network, each device is assigned a Media Access
Control address (MAC address) by the manufacturer for identification. A MAC address
consists of six groups of two hexadecimal digits, separated by hyphens (-) or colons (:), in
transmission order, (for example, 01-23-45-67-89-AB or 01:23:45:67:89:AB).
IP address: Each device must also have an Internet Protocol (IP) address. This address
allows the device to deliver data on a more complex, routed network.
Each IP address is divided into four 8-bit segments and is expressed in a dotted, decimal
format (for example, 211.154.184.16). The first part of the IP address is used for the Network
ID (What network are you on?), and the second part of the address is for the Host ID (unique
for each device on the network). An IP address of 192.168.x.y is a standard designation
recognized as part of a private network that is not routed on the Internet.
Subnet mask: A subnet is a logical grouping of connected network devices. Nodes on a
subnet tend to be located in close physical proximity to each other on a Local Area Network
(LAN). A mask (known as the subnet mask or network mask) defines the boundaries of an IP
subnet.
A subnet mask of 255.255.255.0 is generally suitable for a small local network. This means
that all IP addresses on this network should have the same first 3 octets, and the various
devices on this network are identified by the last octet (8-bit field). An example of this is to
assign a subnet mask of 255.255.255.0 and an IP addresses of 192.168.2.0 through
192.168.2.255 to the devices on a small local network.
The only connection between different subnets is via a router. If subnets are used, an IP
router must be employed.
IP router: Routers are the link between LANs. Using a router, a computer in a LAN can send
messages to any other networks, which might have other LANs behind them. If the
destination of the data is not within the LAN, the router forwards the data to another network
or group of networks where it can be delivered to its destination.
Routers rely on IP addresses to deliver and receive data packets.
IP addresses properties: In
the Properties window,
select the "Ethernet addresses" configuration entry. STEP 7 displays the
Ethernet address configuration dialog, which associates the software project
with the IP address of the
CPU that will receive that
project.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
815
Communication
11.2 PROFINET
Table 11- 5
Parameters for the IP address
Parameter
Subnet
IP protocol
Description
Name of the Subnet to which the device is connected. Click the "Add new subnet" button to create a
new subnet. "Not connected" is the default. Two connection types are possible:
•
The "Not connected" default provides a local connection.
•
A subnet is required when your network has two or more devices.
IP address
Assigned IP address for the CPU
Subnet mask
Assigned subnet mask
Use IP router
Click the checkbox to indicate the use of an IP router
Router address
Assigned IP address for the router, if applicable
Note
All IP addresses are configured when you download the project. If the CPU does not have a
pre-configured IP address, you must associate the project with the MAC address of the
target device. If your CPU is connected to a router on a network, you must also enter the IP
address of the router.
The "Set IP address using a different method" radio button allows you to change the IP
address online or by using the "T_CONFIG (Page 901)" instruction after the program is
downloaded. This IP address assignment method is for the CPU only.
WARNING
Downloading a hardware configuration with "Set IP address using different method"
After downloading a hardware configuration with the "Set IP address using a different
method" option enabled, it is not possible to transition the CPU operating mode from RUN
to STOP or from STOP to RUN.
User equipment continues to run under these conditions and can result in unexpected
machine or process operations, which could cause death, severe personal injury, or
property damage if proper precautions are not taken.
Ensure that your CPU IP address(es) are set before using the CPU in an actual automation
environment. This can be done by using your STEP 7 programming package, the SIMATIC
Automation Tool, or an attached HMI device in conjunction with the T_CONFIG instruction.
S7-1200 Programmable controller
816
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
WARNING
Condition in which PROFINET network might stop
When changing the IP address of a CPU online or from the user program, it is possible to
create a condition in which the PROFINET network might stop.
If the IP address of a CPU is changed to an IP address outside the subnet, the PROFINET
network will lose communication, and all data exchange will stop. User equipment may be
configured to keep running under these conditions. Loss of PROFINET communication may
result in unexpected machine or process operations, causing death, severe personal injury,
or property damage if proper precautions are not taken.
If an IP address must be changed manually, ensure that the new IP address lies within the
subnet.
Configuring the PROFINET port
By default, the CPU configures port(s) of the PROFINET interface for autonegotiation. For
autonegotiation to function properly, you must configure both stations to autonegotiate. If one
station has a fixed configuration (for example, full-duplex at 100 Mbps) and the other station
is set to autonegotiate, then autonegotiation fails, resulting in half-duplex operation.
To overcome this limitation of autonegotiation, the S7-1200 provides an option to disable
autonegotiation. When you disable autonegotiation, the S7-1200 is automatically configured
for full-duplex operation at 100 Mbps.
You can set the transmission rate and duplex to a fixed value for each port:
1. Select Advanced options and the port you need to configure. Then, select Port options.
2. In the Connection, Transmission rate / duplex field, select one of the following:
– Automatic: The CPU and the peer device determine the port’s transmission rate and
duplex by autonegotiation.
– TP 100 Mbps full-duplex: If you disable autonegotiation, the port operates at 100 Mbps
full-duplex. If you enable autonegotiation, the port can operate at 100 Mbps full-duplex
or another transmission rate / duplex that is autonegotiated between the CPU and the
peer device (which places a message in the diagnostic buffer if "Monitor" is selected
(see below)).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
817
Communication
11.2 PROFINET
3. Monitor: When you select this check box, a message is placed in the diagnostic buffer if
any of the following occur at the port:
– A link cannot be established at the port
– An established link fails
– You select "TP 100 Mbps full-duplex" as the Transmission rate / duplex, and the CPU
establishes a link using autonegotiation with the negotiated transmission rate not
equal to 100 Mbps or the negotiated duplex equal to half-duplex.
4. Enable autonegotiation: Once you set the Transmission rate / duplex field to full-duplex at
100 Mbps, you can then disable autonegotiation. Deselect the "Enable autonegotiation"
check box to disable autonegotiation.
Note
If you do not disable autonegotiation, the CPU and the peer device negotiate the port’s
transmission rate and duplex.
S7-1200 Programmable controller
818
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.4
Testing the PROFINET network
After completing the configuration, download the project (Page 216) to the CPU. All IP
addresses are configured when you download the project.
Assigning an IP address to a device online
The S7-1200 CPU does not have a pre-configured IP address. You must manually assign an
IP address for the CPU:
● To assign an IP address to a device online, refer to "Device configuration: Assigning an
IP address to a CPU online" (Page 813) for this step-by-step procedure.
● To assign an IP address in your project, you must configure the IP address in the Device
configuration, save the configuration, and download it to the PLC. Refer to "Device
configuration: Configuring an IP address for a CPU in your project" (Page 814) for more
information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
819
Communication
11.2 PROFINET
Using the "Extended download to device" dialog to test for connected network devices
The S7-1200 CPU "Download to device" function and its "Extended download to device"
dialog can show all accessible network devices and whether or not unique IP addresses
have been assigned to all devices. To display all accessible and available devices with their
assigned MAC or IP addresses, check the "Show all accessible devices" checkbox.
If the required network device is not in this list, communications to that device have been
interrupted for some reason. The device and network must be investigated for hardware
and/or configuration errors.
11.2.5
Locating the Ethernet (MAC) address on the CPU
In PROFINET networking, a Media Access Control address (MAC address) is an identifier
assigned to the network interface by the manufacturer for identification. A MAC address
usually encodes the manufacturer's registered identification number.
The standard (IEEE 802.3) format for printing MAC addresses in human-friendly form is six
groups of two hexadecimal digits, separated by hyphens (-) or colons (:), in transmission
order, (for example, 01-23-45-67-89-ab or 01:23:45:67:89:ab).
Note
Each CPU is loaded at the factory with a permanent, unique MAC address. You cannot
change the MAC address of a CPU.
S7-1200 Programmable controller
820
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
The MAC address is printed on the front, lower-left corner of the CPU. Note that you have to
lift the lower door to see the MAC address information.
①
MAC address
Initially, the CPU has no IP address, only a factory-installed MAC address. PROFINET
communications requires that all devices be assigned a unique IP address.
Use the CPU "Download to device" function and the "Extended
download to device" dialog to
show all accessible network devices and ensure that unique IP
addresses have been assigned to
all devices. This dialog displays all
accessible and available devices
with their assigned MAC or IP
addresses. MAC addresses are
all-important in identifying devices
that are missing the required
unique IP address.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
821
Communication
11.2 PROFINET
11.2.6
Configuring Network Time Protocol (NTP) synchronization
WARNING
If an attacker can access your networks through Network Time Protocol (NTP)
synchronization, the attacker can possibly take limited control of your process by shifting
the CPU system time.
The NTP client feature of the S7-1200 CPU is disabled by default, and, when enabled, only
allows configured IP addresses to act as an NTP server. The CPU disables this feature by
default, and you must configure this feature to allow remotely-controlled CPU system time
corrections.
The S7-1200 CPU supports "time of day" interrupts and clock instructions that depend upon
accurate CPU system time. If you configure NTP and accept time synchronization from a
server, you must ensure that the server is a trusted source. Failure to do so can cause a
security breach that allows an unknown user to take limited control of your process by
shifting the CPU system time.
For security information and recommendations, please see our "Operational Guidelines for
Industrial Security" (http://www.industry.siemens.com/topics/global/en/industrialsecurity/Documents/operational_guidelines_industrial_security_en.pdf) on the Siemens
Service and Support site.
The Network Time Protocol (NTP) is widely used to synchronize the clocks of computer
systems to Internet time servers. In NTP mode, the CPU sends time-of-day queries at
regular intervals (in the client mode) to the NTP server in the subnet (LAN). Based on the
replies from the server, the most reliable and most accurate time is calculated and the time
of day on the station is synchronized.
The advantage of this mode is that it allows the time to be synchronized across subnets.
The IP addresses of up to four NTP servers need to be configured. The update interval
defines the interval between the time queries (in seconds). The value of the interval ranges
between 10 seconds and one day.
In NTP mode, it is generally UTC (Universal Time Coordinated) that is transferred; this
corresponds to GMT (Greenwich Mean Time).
S7-1200 Programmable controller
822
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
In the Properties window, select the "Time synchronization" configuration entry. STEP 7
displays the Time synchronization configuration dialog:
Note
All IP addresses are configured when you download the project.
Table 11- 6
Parameters for time synchronization
Parameter
Definition
Enable time synchronization via NTP
server
Select the checkbox to enable time synchronization via NTP
server.
Server 1
Assigned IP Address for network time server 1
Server 2
Assigned IP Address for network time server 2
Server 3
Assigned IP Address for network time server 3
Server 4
Assigned IP Address for network time server 4
Time synchronization update interval
Interval value (sec)
CPU synchronizes the modules of the
device.
Select the checkbox to synchronize the CP clock with the
CPU clock.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
823
Communication
11.2 PROFINET
11.2.7
PROFINET device start-up time, naming, and address assignment
PROFINET IO can extend the start-up time for your system (configurable time-out). More
devices and slow devices impact the amount of time it takes to switch to RUN.
In V4.0 and later, you can have a maximum of 16 PROFINET IO devices on your S7-1200
PROFINET network.
Each station (or IO device) starts up independently on start-up, and this affects the overall
CPU start-up time. If you set the configurable time-out too low, there may not be a sufficient
overall CPU start-up time for all stations to complete start-up. If this situation occurs, false
station errors will result.
In the CPU Properties under "Startup", you can find the "Parameter assignment time for
distributed I/O" (time-out). The default configurable time-out is 60,000 ms (1 minute); the
user can configure this time.
PROFINET device naming and addressing in STEP 7
All PROFINET devices must have a Device Name and an IP Address. Use STEP 7 to define
the Device Names and to configure the IP addresses. Device names are downloaded to the
IO devices using PROFINET DCP (Discovery and Configuration Protocol).
PROFINET address assignment at system start-up
The controller broadcasts the names of the devices to the network, and the devices respond
with their MAC addresses. The controller then assigns an IP address to the device using
PROFINET DCP protocol:
● If the MAC address has a configured IP address, then the station performs start-up.
● If the MAC address does not have a configured IP address, STEP 7 assigns the address
that is configured in the project, and the station then performs start-up.
● If there is a problem with this process, a station error occurs and no start-up takes place.
This situation causes the configurable time-out value to be exceeded.
S7-1200 Programmable controller
824
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8
Open user communication
11.2.8.1
Protocols
The integrated PROFINET port of the CPU supports multiple communications standards
over an Ethernet network:
● Transport Control Protocol (TCP)
● ISO on TCP (RFC 1006)
● User Datagram Protocol (UDP)
Table 11- 7
Protocols and communication instructions for each
Protocol
Usage examples
Entering data in the
receive area
Communication instruc- Addressing type
tions
TCP
CPU-to-CPU communication
Ad hoc mode
Only TRCV_C and
TRCV
Transport of frames
Data reception with
specified length
TSEND_C, TRCV_C,
TCON, TDISCON,
TSEND, and TRCV
CPU-to-CPU communication
Ad hoc mode
Only TRCV_C and
TRCV
Message fragmentation and re-assembly
Protocol-controlled
TSEND_C, TRCV_C,
TCON, TDISCON,
TSEND, and TRCV
CPU-to-CPU communication
User Datagram Protocol
TUSEND and TURCV
Assigns port numbers to
the Local (active) and
Partner (passive) devices, but is not a dedicated connection
Data transmission and
reception with specified
length
GET and PUT
Assigns TSAPs to the
Local (active) and Partner (passive) devices
Data transmission and
reception with specified
length
Built-in
Built-in
ISO on TCP
UDP
User program communications
S7 communication
CPU-to-CPU communication
Read/write data
from/to a CPU
PROFINET IO
CPU-to-PROFINET
IO device communication
Assigns port numbers to
the Local (active) and
Partner (passive) devices
Assigns TSAPs to the
Local (active) and Partner (passive) devices
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
825
Communication
11.2 PROFINET
11.2.8.2
TCP and ISO on TCP
Transport Control Protocol (TCP) is a standard protocol described by RFC 793:
Transmission Control Protocol. The primary purpose of TCP is to provide reliable, secure
connection service between pairs of processes. This protocol has the following features:
● An efficient communications protocol since it is closely tied to the hardware
● Suitable for medium-sized to large data amounts (up to 8192 bytes)
● Provides considerably more facilities for applications, notably error recovery, flow control,
and reliability
● A connection-oriented protocol
● Can be used very flexibly with third-party systems which exclusively support TCP
● Routing-capable
● Only static data lengths are applicable.
● Messages are acknowledged.
● Applications are addressed using port numbers.
● Most of the user application protocols, such as TELNET and FTP, use TCP.
● Programming effort is required for data management due to the SEND / RECEIVE
programming interface.
International Standards Organization (ISO) on Transport Control Protocol (TCP) (RFC 1006)
(ISO on TCP) is a mechanism that enables ISO applications to be ported to the TCP/IP
network. This protocol has the following features:
● An efficient communications protocol closely tied to the hardware
● Suitable for medium-sized to large data amounts (up to 8192 bytes)
● In contrast to TCP, the messages feature an end-of-data identification and are messageoriented.
● Routing-capable; can be used in WAN
● Dynamic data lengths are possible.
● Programming effort is required for data management due to the SEND / RECEIVE
programming interface.
Using Transport Service Access Points (TSAPs), TCP protocol allows multiple connections
to a single IP address (up to 64K connections). With RFC 1006, TSAPs uniquely identify
these communication end point connections to an IP address.
S7-1200 Programmable controller
826
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8.3
Communication services and used port numbers
The S7-1200 CPU supports the protocols listed in the table below. For each protocol, the
CPU assigns the address parameters, the respective communications layer as well as the
communications role, and the communications direction.
This information makes it possible to match the security measures for protection of the
automation system to the used protocols (for example, firewall). Only the Ethernet or
PROFINET networks have security measures. Since PROFIBUS does not have any security
measures, the table does not include any PROFIBUS protocols.
The table below shows the different layers and protocols that the CPU uses:
Protocol
Port number
(2) Link layer
Function
(4) Transport layer
Description
(2) Ethernet II and
IEEE 802.1Q and
Ethertype 0x8892
(PROFINET)
PROFINET uses
DCP to discover
devices and provide basic settings.
PROFINET protocols
DCP
(Discovery and
Configuration
Protocol)
Not relevant
Accessible devices PROFINET
Discovery and
configuration
DCP uses the
special multicast
MAC address: xxxx-xx-01-0E-CF,
xx-xx-xx = Organizationally Unique
Indentifier
LLDP
(Link Layer Discovery Protocol)
Not relevant
(2) Ethernet II and PROFINET Link
IEEE 802.1Q and Layer Discovery
Ethertype 0x88CC protocol
(PROFINET)
PROFINET uses
LLDP to discover
and manage
neighbor relationships between
PROFINET devices.
LLDP uses the
special multicast
MAC address: 0180-C2-00-00-0E
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
827
Communication
11.2 PROFINET
11.2.8.4
Ad hoc mode
Typically, TCP and ISO-on-TCP receive data packets of a specified length, ranging from 1 to
8192 bytes. However, the TRCV_C and TRCV communication instructions also provide an
"ad hoc" communications mode that can receive data packets of a variable length from 1 to
1472 bytes.
Note
If you store the data in an "optimized" DB (symbolic only), you can receive data only in
arrays of Byte, Char, USInt, and SInt data types.
To configure the TRCV_C or TRCV instruction for ad hoc mode, set the ADHOC instruction
input parameter.
If you do not call the TRCV_C or TRCV instruction in ad hoc mode frequently, you could
receive more than one packet in one call. For example: If you were to receive five 100-byte
packets with one call, TCP would deliver these five packets as one 500-byte packet, while
ISO-on-TCP would restructure the packets into five 100-byte packets.
11.2.8.5
Connection IDs for the Open user communication instructions
When you insert the TSEND_C, TRCV_C or TCON PROFINET instructions into your user
program, STEP 7 creates an instance DB to configure the communications channel (or
connection) between the devices. Use the "Properties" (Page 807) of the instruction to
configure the parameters for the connection. Among the parameters is the connection ID for
that connection.
● The connection ID must be unique for the CPU. Each connection that you create must
have a different DB and connection ID.
● Both the local CPU and the partner CPU can use the same connection ID number for the
same connection, but the connection ID numbers are not required to match. The
connection ID number is relevant only for the PROFINET instructions within the user
program of the individual CPU.
● You can use any number for the connection ID of the CPU. However, configuring the
connection IDs sequentially from "1" provides an easy method for tracking the number of
connections in use for a specific CPU.
Note
Each TSEND_C, TRCV_C or TCON instruction in your user program creates a new
connection. It is important to use the correct connection ID for each connection.
S7-1200 Programmable controller
828
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
The following example shows the communication between two CPUs that utilize two
separate connections for sending and receiving the data.
● The TSEND_C instruction in CPU_1 links to the TRCV_C in CPU_2 over the first
connection ("connection ID 1" on both CPU_1 and CPU_2).
● The TRCV_C instruction in CPU_1 links to the TSEND_C in CPU_2 over the second
connection ("connection ID 2" on both CPU_1 and CPU_2).
① TSEND_C on CPU_1 creates a con-
nection and assigns a connection ID
to that connection (connection ID 1 for
CPU_1).
② TRCV_C on CPU_2 creates the connection for CPU_2 and assigns the
connection ID (connection ID 1 for
CPU_2).
③ TRCV_C on CPU_1 creates a second
connection for CPU_1 and assigns a
different connection ID for that connection (connection ID 2 for CPU_1).
④ TSEND_C on CPU_2 creates a sec-
ond connection and assigns a different
connection ID for that connection
(connection ID 2 for CPU_2).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
829
Communication
11.2 PROFINET
The following example shows the communication between two CPUs that utilize 1
connection for both sending and receiving the data.
● Each CPU uses a TCON instruction to configure the connection between the two CPUs.
● The TSEND instruction in CPU_1 links to the TRCV instruction in CPU_2 by using the
connection ID ("connection ID 1") that was configured by the TCON instruction in CPU_1.
The TRCV instruction in CPU_2 links to the TSEND instruction in CPU_1 by using the
connection ID ("connection ID 1") that was configured by the TCON instruction in CPU_2.
● The TSEND instruction in CPU_2 links to the TRCV instruction in CPU_1 by using the
connection ID ("connection ID 1") that was configured by the TCON instruction in CPU_2.
The TRCV instruction in CPU_1 links to the TSEND instruction in CPU_2 by using the
connection ID ("connection ID 1") that was configured by the TCON instruction in CPU_1.
① TCON on CPU_1 creates a connection and assigns a connection ID for
that connection on CPU_1 (ID=1).
② TCON on CPU_2 creates a connection and assigns a connection ID for
that connection on CPU_2 (ID=1).
③ TSEND and TRCV on CPU_1 use the
connection ID created by the TCON
on CPU_1 (ID=1).
TSEND and TRCV on CPU_2 use the
connection ID created by the TCON
on CPU_2 (ID=1).
S7-1200 Programmable controller
830
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
As shown in the following example, you can also use individual TSEND and TRCV
instruction to communication over a connection created by a TSEND_C or TRCV_C
instruction. The TSEND and TRCV instructions do not themselves create a new connection,
so you must use the DB and connection ID that was created by a TSEND_C, TRCV_C or
TCON instruction.
① TSEND_C on CPU_1 creates a con-
nection and assigns a connection ID
to that connection (ID=1).
② TRCV_C on CPU_2 creates a connection and assigns the connection ID to
that connection on CPU_2 (ID=1).
③ TSEND and TRCV on CPU_1 use the
connection ID created by the
TSEND_C on CPU_1 (ID=1).
TSEND and TRCV on CPU_2 use the
connection ID created by the TRCV_C
on CPU_2 (ID=1).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
831
Communication
11.2 PROFINET
11.2.8.6
Parameters for the PROFINET connection
The TSEND_C, TRCV_C and TCON instructions require connection-related parameters in
order to connect to the partner device. The TCON_Param structure assigns these
parameters for the TCP, ISO-on-TCP, and UDP protocols. Typically, you use the
"Configuration" (Page 807) tab of the "Properties" of the instruction to specify these
parameters. If the "Configuration" tab is not accessible, then you must provide the
TCON_Param structure in the instruction parameters.
With V4.1, the TCON_IP_V4 structure assigns parameters for the TCP protocol, and the
TCON_IP_RFC structure assigns parameters for the ISO-on-TCP protocol.
TCON_Param
Table 11- 8
Structure of the connection description (TCON_Param)
Byte
Parameter and data type
0…1
block_length
UInt
Description
Length: 64 bytes (fixed)
2…3
id
CONN_OUC
(Word)
Reference to this connection: Range of values: 1 (default) to 4095.
Specify the value of this parameter for the TSEND_C, TRCV_C or
TCON instruction under ID.
4
connection_type
USInt
Connection type:
•
5
active_est
Bool
17: TCP (default)
•
18: ISO-on-TCP
•
19: UDP
ID for the type of connection:
•
•
TCP and ISO-on-TCP:
–
FALSE: Passive connection
–
TRUE: Active connection (default)
UDP: FALSE
6
local_device_id
USInt
ID for the local PROFINET or Industrial Ethernet interface:
1 (default)
7
local_tsap_id_len
USInt
Length of parameter local_tsap_id used, in bytes; possible values:
•
TCP: 0 (active, default) or 2 (passive)
•
ISO-on-TCP: 2 to 16
•
UDP: 2
8
rem_subnet_id_len
USInt
This parameter is not used.
9
rem_staddr_len
USInt
Length of address of partner end point, in bytes:
10
rem_tsap_id_len
USInt
•
0: unspecified (parameter rem_staddr is irrelevant)
•
4 (default): Valid IP address in parameter rem_staddr (only for
TCP and ISO-on-TCP)
Length of parameter rem_tsap_id used, in bytes; possible values:
•
TCP: 0 (passive) or 2 (active, default)
•
ISO-on-TCP: 2 to 16
•
UDP: 0
S7-1200 Programmable controller
832
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Byte
Parameter and data type
11
next_staddr_len
USInt
Description
This parameter is not used.
12 … 27
local_tsap_id
Array [1..16] of
Byte
Local address component of connection:
•
•
TCP and ISO-on-TCP: local port no. (possible values: 1 to
49151; recommended values: 2000...5000):
–
local_tsap_id[1] = high byte of port number in hexadecimal
notation;
–
local_tsap_id[2] = low byte of port number in hexadecimal
notation;
–
local_tsap_id[3-16] = irrelevant
ISO-on-TCP: local TSAP-ID:
–
local_tsap_id[1] = B#16#E0;
–
local_tsap_id[2] = rack and slot of local end points (bits 0 to
4: slot number, bits 5 to 7: rack number);
–
local_tsap_id[3-16] = TSAP extension, optional
• UDP: This parameter is not used.
Note: Make sure that every value of local_tsap_id is unique within
the CPU.
28 … 33
rem_subnet_id
Array [1..6] of
USInt
This parameter is not used.
34 … 39
rem_staddr
Array [1..6] of
USInt
TCP and ISO-on-TCP only: IP address of the partner end point.
(Not relevant for passive connections.) For example, IP address
192.168.002.003 is stored in the following elements of the array:
rem_staddr[1] = 192
rem_staddr[2] = 168
rem_staddr[3] = 002
rem_staddr[4] = 003
rem_staddr[5-6]= irrelevant
40 … 55
rem_tsap_id
Array [1..16] of
Byte
Partner address component of connection
•
•
•
TCP: partner port number. Range: 1 to 49151; Recommended
values: 2000 to 5000):
–
rem_tsap_id[1] = high byte of the port number in hexadecimal notation
–
rem_tsap_id[2] = low byte of the port number in hexadecimal notation;
–
rem_tsap_id[3-16] = irrelevant
ISO-on-TCP: partner TSAP-ID:
–
rem_tsap_id[1] = B#16#E0
–
rem_tsap_id[2] = rack and slot of partner end point (bits 0
to 4: Slot number, bits 5 to 7: rack number)
–
rem_tsap_id[3-16] = TSAP extension, optional
UDP: This parameter is not used.
56 … 61
next_staddr
Array [1..6] of
Byte
This parameter is not used.
62 … 63
spare
Word
Reserved: W#16#0000
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
833
Communication
11.2 PROFINET
TCON_IP_V4
Table 11- 9
Structure of the connection description (TCON_IP_V4): For use with TCP
Byte
Parameter and data type
0…1
InterfaceId
HW_ANY
HW-identifier of the IE-interface submodule
2…3
ID
CONN_OUC
(Word)
Reference to this connection: Range of values: 1 (default) to 4095.
Specify the value of this parameter for the TSEND_C, TRCV_C, or
TCON instruction under ID.
4
ConnectionType
Byte
Connection type:
5
ActiveEstablished
Description
Bool
•
11: TCP/IP (default)
•
17: TCP/IP (This connection type is included for legacy reasons. It is recommended that you use "11: TCP/IP (default)".)
•
19: UDP
Active/passive connection establishment:
•
TRUE: Active connection (default)
•
FALSE: Passive connection
V4 IP address
6
ADDR[1]
Byte
Octet 1
7
ADDR[1]
Byte
Octet 2
8
ADDR[1]
Byte
Octet 3
9
ADDR[1]
Byte
Octet 4
10 ... 11
RemotePort
UInt
Remote UDP/TCP port number
12 ... 13
LocalPort
UInt
Local UDP/TCP port number
S7-1200 Programmable controller
834
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TCON_IP_RFC
Table 11- 10 Structure of the connection description (TCON_IP_RFC): For use with ISO on TCP
Byte
Parameter and data type
0…1
InterfaceId
HW_ANY
HW-identifier of the IE-interface submodule
2…3
ID
CONN_OUC
(Word)
Reference to this connection: Range of values: 1 (default) to 4095.
Specify the value of this parameter for the TSEND_C, TRCV_C, or
TCON instruction under ID.
4
ConnectionType
Byte
Connection type:
5
6 ... 7
ActiveEstablished
Description
Bool
Spare
•
12: ISO-on-TCP (default)
•
17: ISO-on-TCP (This connection type is included for legacy
reasons. It is recommended that you use "12: ISO-on-TCP
(default)".)
Active/passive connection establishment:
•
TRUE: Active connection (default)
•
FALSE: Passive connection
Not used
V4 IP address
8
ADDR[1]
Byte
Octet 1
9
ADDR[1]
Byte
Octet 2
10
ADDR[1]
Byte
Octet 3
11
ADDR[1]
Byte
Octet 4
Remote transport selector
12 ... 13
TSelLength
UInt
Length of TSelector
14 ... 45
TSel
array [1..32] of
Byte
Character array for TSAP name
Local transport selector
46 ... 47
TSelLength
UInt
Length of TSelector
48 ... 79
TSel
array [1..32] of
Byte
Character array for TSAP name
See also
S7-1200 CM/CPs (https://support.industry.siemens.com/cs/us/en/ps)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
835
Communication
11.2 PROFINET
11.2.8.7
TSEND_C and TRCV_C instructions
As of version V4.1 of the S7-1200 CPU together with STEP 7 V13 SP1, the CPU extends the
capability of the TSEND_C and TRCV_C instructions to use connection parameters with
structures according to "TCON_IP_v4" and "TCON_IP_RFC".
For this reason, the S7-1200 supports two sets of TSEND_C and TRCV_C instructions:
● Legacy TSEND_C and TRCV_C instructions (Page 848): These TSEND_C and TRCV_C
instructions existed prior to version V4.0 of the S7-1200 and only work with connection
parameters with structures according to "TCON_Param".
● TSEND_C and TRCV_C instructions (Page 837): These TSEND_C and TRCV_C
instructions provide all of the functionality of the legacy instructions, plus the ability to use
connection parameters with structures according to "TCON_IP_v4" and "TCON_IP_RFC".
Selecting the version of the TSEND_C and TRCV_C instructions
There are two versions of the TSEND_C and TRCV_C instructions available in STEP 7:
● Versions 2.5 and 3.1 were available in STEP 7 Basic/Professional V13 or earlier.
● Version 4.0 is available in STEP 7 Basic/Professional V13 SP1 or later.
For compatibility and ease of migration, you can choose which instruction version to insert
into your user program.
Do not use different instruction versions in the same CPU program.
Click the icon on the instruction tree task card to enable the headers and columns
of the instruction tree.
To change the version of the TSEND_C and
TRCV_C instructions, select the version from
the drop-down list. You can select the group
or individual instructions.
When you use the instruction tree to place a TSEND_C or TRCV_C instruction in your
program, a new FB or FC instance, depending on the TSEND_C or TRCV_C instruction
selected, is created in the project tree. You can see new FB or FC instance in the project
tree under PLC_x > Program blocks > System blocks > Program resources.
To verify the version of a TSEND_C or TRCV_C instruction in a program, you must inspect
project tree properties and not the properties of a box displayed in the program editor. Select
a project tree TSEND_C or TRCV_C FB or FC instance, right-click, select "Properties", and
select the "Information" page to see the TSEND_C or TRCV_C instruction version number.
S7-1200 Programmable controller
836
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TSEND_C and TRCV_C (Send and receive data using Ethernet)
The TSEND_C instruction combines the functions of the TCON, TDISCON and TSEND
instructions. The TRCV_C instruction combines the functions of the TCON, TDISCON, and
TRCV instructions. (Refer to "TCON, TDISCON, TSEND, AND TRCV (Page 857)" for more
information on these instructions.)
The minimum size of data that you can transmit (TSEND_C) or receive (TRCV_C) is one
byte; the maximum size is 8192 bytes. TSEND_C does not support the transmission of data
from Boolean locations, and TRCV_C will not receive data into Boolean locations. For
information on transferring data with these instructions, see the section on data consistency
(Page 198).
Note
Initializing the communication parameters
After you insert the TSEND_C or TRCV_C instruction, use the "Properties" of the instruction
(Page 807) to configure the communication parameters (Page 832). As you enter the
parameters for the communication partners in the inspector window, STEP 7 enters the
corresponding data in the DB for the instruction.
If you want to use a multi-instance DB, you must manually configure the DB on both CPUs.
Table 11- 11 TSEND_C and TRCV_C instructions
LAD / FBD
1
SCL
"TSEND_C_DB"(
req:=_bool_in_,
cont:=_bool_in_,
len:=_uint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
connect:=_struct_inout_,
data:=_variant_inout_,
com_rst:=_bool_inout_);
"TRCV_C_DB"(
en_r:=_bool_in_,
cont:=_bool_in_,
len:=_uint_in_,
adhoc:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
rcvd_len=>_uint_out_,
connect:=_struct_inout_,
data:=_variant_inout_,
com_rst:=_bool_inout_);
Description
TSEND_C establishes a TCP or ISO on TCP
communication connection to a partner station,
sends data, and can terminate the connection.
After the connection is set up and established, it
is automatically maintained and monitored by
the CPU.
TRCV_C establishes a TCP or ISO on TCP
communication connection to a partner CPU,
receives data, and can terminate the connection.
After the connection is set up and established, it
is automatically maintained and monitored by
the CPU.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
837
Communication
11.2 PROFINET
Table 11- 12 TSEND_C and TRCV_C data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
Starts the send job on a rising edge
IN
Bool
Receive enable
IN
Bool
Controls the communication connection:
(TSEND_C)
EN_R
(TRCV_C)
CONT
•
0: Disconnect the communication connection after data is
sent.
• 1: Establish and maintain the communication connection.
When sending data (TSEND_C) (rising edge at the REQ parameter) or receiving data (TRCV_C) (rising edge at the EN_R
parameter), the CONT parameter must have the value TRUE in
order to establish or maintain a connection.
LEN
IN
UDInt
Optional parameter (hidden)
Maximum number of bytes to be sent (TSEND_C) or received
(TRCV_C) with the job. If you use purely symbolic values at the
DATA parameter, the LEN parameter must have the value "0".
ADHOC
(TRCV_C)
IN
CONNECT
IN_OUT
Bool
Optional parameter (hidden)
Ad hoc mode request for connection type TCP.
TCON_Param
Pointer to the connection description corresponding to the structure of connection to be described:
•
For TCP or UDP, use the structure TCON_IP_v4
•
For further information on TCON_IP_v4, refer to: "Parameters for the PROFINET connection" (Page 832).
•
For ISO-on-TCP, use the structure TCON_IP_RFC
For further information on TCON_IP_RFC, refer to: "Parameters for the PROFINET connection" (Page 832).
The CONNECT parameter is only evaluated upon a positive
edge at REQ (TSEND_C), when connection establishment
starts (TRCV_C), or when COM_RST = 1.
•
DATA
ADDR
IN_OUT
IN_OUT
Variant
Variant
Pointer to the send area containing:
•
Address and length of data to be sent (TSEND_C)
•
Address and maximum length of received data (TRCV_C)
Optional parameter (hidden)
Pointer to the address of the recipient with the connection type
UDP. The address information is mapped in the structure
TADDR_Param ###.
S7-1200 Programmable controller
838
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Parameter and type
Data type
Description
COM_RST
Bool
Optional parameter (hidden)
IN_OUT
Restarts the instruction:
•
0: Irrelevant
1: Completely restarts the instruction; the existing connection is either terminated or reset and established again in
accordance with CONT.
The COM_RST parameter is reset after evaluation by the
TSEND_C or TRCV_C instruction and should not, therefore, be
switched statically.
•
DONE
BUSY
ERROR
OUT
OUT
OUT
Bool
Bool
Bool
Status parameter with the following values:
•
0: Send job not yet started or is still executing.
•
1: Send job executed without errors. This state is only displayed for one cycle.
Status parameter with the following values:
•
0: Send job not yet started or already completed.
•
1: Send job not yet completed. A new send job cannot be
started.
Status parameters with the following values:
•
0: No error
•
1: Error occurred during connection establishment, data
transmission, or connection termination.
STATUS
OUT
Word
Status of instruction (see the ERROR and STATUS parameters
description).
RCVD_LEN
OUT
Int
Amount of data actually received (in bytes).
(TRCV_C)
Note
The TSEND_C instruction requires a low-to-high transition at the REQ input parameter to
start a send job. The BUSY parameter is then set to 1 during processing. Completion of the
send job is indicated by either the DONE or ERROR parameters being set to 1 for one scan.
During this time, any low-to-high transition at the REQ input parameter is ignored.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
839
Communication
11.2 PROFINET
Note
The default setting of the LEN parameter (LEN = 0) uses the DATA parameter to determine
the length of the data being transmitted. It is recommended that the data transmitted by the
TSEND_C instruction be the same size as the DATA parameter of the TRCV_C instruction.
If using the default setting of the LEN parameter and it is necessary to send the data in
segments smaller than the DATA parameter size, the following applies. If the size of the data
transmitted from TSEND_C does not equal the TRCV_C DATA parameter size, TRCV_C
remains in a busy status (status code: 7006) until the overall size of the data transmitted
from TSEND_C equals the TRCV_C DATA parameter size.
The TRCV_C DATA parameter buffer does not display the new data received until the data
size equals the DATA parameter buffer size.
S7-1200 Programmable controller
840
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TSEND_C operations
The TSEND_C instruction is executed asynchronously and implements the following
functions in sequence:
1. Setting up and establishing a communications connection:
TSEND_C sets up a communication connection and establishes this connection if a rising
edge is detected at the REQ parameter and no communication connection is in place yet.
Once the connection has been set up and established, it is automatically maintained and
monitored by the CPU. The connection description specified at the CONNECT parameter
is used to set up the communications connection. The following connection types can be
used:
– TCON_Param structure for the TCP, ISO-on-TCP, and UDP protocols
– WIth V4.1, TCP/UDP: Connection description using the structure TCON_IP_v4 at the
parameter CONNECT
– WIth V4.1, ISO-on-TCP: Connection description using the structure TCON_IP_RFC at
the parameter CONNECT
An existing connection is terminated and the connection which has been set up is
removed when the CPU goes into STOP mode. To set up and establish the connection
again, you must execute TSEND_C again. For information on the number of possible
communication connections, please refer to the technical specifications for your CPU.
2. Sending data via an existing communications connection:
The send job is executed when a rising edge is detected at the REQ parameter. As
described above, the communications connection is established first. You specify the
send area with the DATA parameter. This includes the address and the length of the data
to be sent. Do not use a data area with the data type BOOL or Array of BOOL at the
DATA parameter. With the LEN parameter, you specify the maximum number of bytes
sent with a send job. If using a symbolic name at the DATA parameter, the LEN
parameter should have the value "0".
The data to be sent must not be edited until the send job is completed.
3. Terminating the communications connection:
The communications connection is terminated after the data has been sent if the CONT
parameter had the value "0" at the time of the rising edge at the REQ parameter.
Otherwise, the communications connection will be maintained.
If the send job executes successfully, the DONE parameter is set to "1". The
communications connection may be terminated before this (see the above description of the
dependency on the CONT parameter). Signal state "1" at the DONE parameter is not
confirmation that the data sent has already been read by the communications partner.
TSEND_C is reset when the COM_RST parameter is set to "1". Data loss may occur if data
is being transferred at this point.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
841
Communication
11.2 PROFINET
The following scenarios are possible depending on the CONT parameter:
● CONT = "0":
An existing communications connection is established.
● CONT = "1" and a communications connection was established:
An existing communications connection is reset and established again.
● CONT = "1" and no communications connection was established.
No communications connection is established.
The COM_RST parameter is reset following evaluation by the instruction T_SEND. To
enable TSEND_C again after the execution (DONE = 1), call the instruction once with REQ =
0
S7-1200 Programmable controller
842
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TRCV_C operations
The TRCV_C instruction is executed asynchronously and implements the following functions
in sequence:
1. Setting up and establishing a communications connection:
TRCV_C sets up a communication connection and establishes this connection if the
EN_R parameter = "1" and there is no communication connection. Once the connection
has been set up and established, it is automatically maintained and monitored by the
CPU.
The connection description specified at the CONNECT parameter is used to set up the
communications connection. The following connection types can be used:
– TCON_Param structure for the TCP, ISO-on-TCP, and UDP protocols
– With V4.1, TCP / UDP: Connection description via the structure TCON_IP_v4 at the
parameter CONNECT
– With V4.1, ISO-on-TCP: Connection description via the structure TCON_IP_RFC at
the parameter CONNECT
An existing connection is terminated and the connection which has been set up is
removed when the CPU goes into STOP mode. To set up and establish the connection
again, you must execute TRCV_C again with EN_R = "1".
If EN_R is set to "0" before the communications connection has been established, the
connection will be established and remain in place even if CONT = "0". However, no data
will be received (DONE will remain "0").
For information on the number of possible communication connections, please refer to
the technical specifications for your CPU.
2. Receiving data via an existing communications connection:
Receipt of data is enabled when the EN_R parameter is set to the value "1". As described
above, the communications connection is established first. The received data is entered
in a receive area. You specify the length of the receive area either with the LEN
parameter (if LEN <> 0) or with the length information of the DATA parameter (if LEN =
0), depending on the protocol variant being used. If you use purely symbolic values at the
DATA parameter, the LEN parameter must have the value "0".
If EN_R is set to "0" before data is received for the first time, the communication
connection will remain in place even if CONT = 0. However, no data will be received
(DONE will remain "0").
3. Terminating the communications connection:
The communications connection is terminated after data has been received if the CONT
parameter had the value "0" when connection established was started. Otherwise, the
communications connection will be maintained.
If the receive job executes successfully, the DONE parameter is set to "1". The
communications connection may be terminated before this (see the above description of the
dependency on the CONT parameter).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
843
Communication
11.2 PROFINET
TRCV_C is reset when the COM_RST parameter is set. If data is being received when it
executes again, this can lead to a loss of data. The following scenarios are possible
depending on the CONT parameter:
● CONT = "0":
An existing communications connection is established.
● CONT = "1" and a communications connection was established:
An existing communications connection is reset and established again.
● CONT = "1" and no communications connection was established:
No communications connection is established.
The COM_RST parameter is reset following evaluation by the instruction TRCV_".
TRCV_C handles the same receive modes as the TRCV instruction. The following table
shows how data is entered in the receive area:
Protocol variant
Availability of data in the receive
area
Connection_type parameter of
the connection description
LEN
parameter
RCVD_LEN
parameter
TCP
The data is immediately available.
B#16#11
Selected with
the TRCV_C
instruction
ADHOC input
1 to 1472
TCP (data receipt
with specified
length)
The data is available as soon as
the data length specified at the
LEN parameter has been fully
received.
B#16#11
1 to 8192
Identical to the
value at the
LEN parameter
ISO on TCP (protocol-controlled
data transfer)
The data is available as soon as
the data length specified at the
LEN parameter has been fully
received.
B#16#12
1 to 8192
Identical to the
value at the
LEN parameter
(Ad hoc mode)
Note
Ad hoc mode
The "ad hoc mode" is only available with the TCP protocol variant. To configure the TRCV_C
instruction for ad hoc mode, set the ADHOC instruction input parameter. The length of the
receive area is defined by the pointer at the DATA parameter. The data length actually
received is output at the RCVD_LEN parameter. A maximum of 1460 bytes can be received.
Note
Importing of S7-300/400 STEP 7 projects containing "ad hoc mode" into the S7-1200
In S7-300/400 STEP 7 projects, "ad hoc mode" is selected by assigning "0" to the LEN
parameter. In the S7-1200, you configure the TRCV_C instruction for ad hoc mode by setting
the ADHOC instruction input parameter..
If you import an S7-300/400 STEP 7 project containing "ad hoc mode" into the S7-1200, you
must change the LEN parameter to "65535".
S7-1200 Programmable controller
844
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Note
TCP (data receipt with specified length)
You use the value of the LEN parameter to specify the length for the data receipt. The data
specified at the DATA parameter is available in the receive area as soon as the length
specified at the LEN parameter has been completely received.
Note
ISO on TCP (protocol-controlled data transfer)
With the ISO on TCP protocol variant, data is transferred protocol-controlled. The receive
area is defined by the LEN and DATA parameters.
BUSY, DONE, and ERROR parameters
Note
Due to the asynchronous processing of TSEND_C, you must keep the data in the sender
area consistent until the DONE parameter or the ERROR parameter assumes the value
TRUE.
For TSEND_C, a TRUE state at the parameter DONE means that the data was sent
successfully. It does not mean that the connection partner CPU actually read the receive
buffer.
Due to the asynchronous processing of TRCV_C, the data in the receiver area are only
consistent when parameter DONE = 1.
Table 11- 13 TSEND_C and TRCV_C instructions BUSY, DONE, and ERROR parameters
BUSY
DONE
ERROR
Description
1
0
0
The send job is being processed.
0
1
0
The send job was completed successfully.
0
0
1
The connection establishment or the send job was completed with an error. The cause
of the error is specified in the STATUS parameter.
0
0
0
No new send job was assigned.
You can check the status of the execution with the BUSY, DONE, ERROR, and STATUS
parameters. The BUSY parameter indicates the processing status. With the DONE
parameter, you can check whether or not a send job executed successfully. The ERROR
parameter is set when errors occurred during execution of TSEND_C or TRCV_C. The error
information is output at the STATUS parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
845
Communication
11.2 PROFINET
Error and Status parameters
Table 11- 14 TSEND_C and TRCV_C condition codes for ERROR and STATUS
ERROR
STATUS
Description
(W#16#...)
0
0000
Send (TSEND_C) or receive (TRCV_C) job executed without errors.
0
7000
No active send job execution; no communications connection established.
0
7001
•
Start send (TSEND_C) or receive (TRCV_C) job execution.
•
Establish connection.
•
Wait for connection partner.
0
7002
Data is being sent (TSEND_C) or received (TRCV_C).
0
7003
Communications connection is being terminated.
0
7004
Communications connection established and monitored; no send (TSEND_C) or receive
(TRCV_C) job execution active.
0
7005
Communications connection is being reset.
1
80A0
Group error for error codes W#16#80A1 and W#16#80A2.
1
80A1
•
Connection or port already being used by user.
•
Communication error:
–
The specified connection has not yet been established.
–
The specified connection is being terminated. Transfer through this connection is not
possible.
–
The interface is being re-initialized.
1
80A2
Local or remote port is being used by the system.
1
80A3
•
Attempt being made to re-establish an existing connection.
•
Attempt being made to terminate a non-existent connection.
1
80A4
IP address of the remote endpoint of the connection is invalid, which means it corresponds to
the IP address of the local partner.
1
80A7
Communication error: You called the instruction with COM_RST = 1 before the send job was
complete.
1
80B2
The CONNECT parameter points to a data block that was generated with the attribute "Only
store in load memory".
1
80B3
Inconsistent parameter assignment: Group error for error codes W#16#80A0 to W#16#80A2,
W#16#80A4, W#16#80B4 to W#16#80B9.
1
80B4
You have violated one or both of the following conditions for passive connection establishment
(active_est = FALSE) when using the ISO on TCP protocol variant (connection_type =
B#16#12):
•
local_tsap_id_len >= B#16#02
•
local_tsap_id[1] = B#16#E0
1
80B5
Only passive connection establishment is permitted for connection type 13 = UDP.
1
80B6
Parameter assignment error in the connection_type parameter of the data block for connection
description.
1
80B7
Error in one of the following parameters of the data block for connection description:
block_length, local_tsap_id_len, rem_subnet_id_len, rem_staddr_len, rem_tsap_id_len,
next_staddr_len.
S7-1200 Programmable controller
846
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
ERROR
STATUS
Description
(W#16#...)
1
1
8085
8086
•
The LEN parameter is larger than the highest permitted value.
•
The value at the LEN or DATA parameter was changed after the first call.
The ID parameter within the CONNECT parameter is outside the permitted range.
1
8087
Maximum number of connections reached; no additional connection possible.
1
8088
The value at the LEN parameter does not correspond to the receive area set at the DATA
parameter.
1
8089
The CONNECT parameter does not point to a data block.
1
8091
Maximum nesting depth exceeded.
1
809A
The CONNECT parameter points to a field that does not correspond to the length of the connection description.
1
809B
The ID of the local device in the connection description does not correspond to the CPU.
1
80C3
•
All connection (Page 828) resources are in use.
•
A block with this ID is already being processed in a different priority group.
1
80C4
Temporary communication error:
•
The connection cannot be established at this time.
•
The interface is receiving new parameters or the connection is being established.
•
The configured connection is being removed by a "TDISCON (Page 857)" instruction.
•
The connection used is being terminated by a call with COM_RST = 1.
1
8722
Error in the CONNECT parameter: Invalid source area (area not declared in data block).
1
873A
Error in the CONNECT parameter: Access to connection description is not possible (no access
to data block).
1
877F
Error in the CONNECT parameter: Internal error
1
8822
TSEND_C: DATA parameter: Invalid source area, the area does not exist in the DB.
1
8824
TSEND_C: DATA parameter: Area error in the VARIANT pointer.
1
8832
TSEND_C: DATA parameter: The DB number is too high.
1
883A
TSEND_C: CONNECT parameter: Access to specified connection data not possible (for example, because the DB does not exist).
1
887F
TSEND_C: DATA parameter: Internal error (for example, invalid VARIANT reference)
1
893A
TSEND_C: DATA parameter: Access to send area not possible (for example, because the DB
does not exist).
1
8922
TRCV_C: DATA parameter: Invalid target area; the area does not exist in the DB.
1
8924
TRCV_C: DATA parameter: Area error in the VARIANT pointer.
1
8932
TRCV_C: DATA parameter: The DB number is too high.
1
893A
TRCV_C: CONNECT parameter: Access to specified connection data not possible (for example, because the DB does not exist).
1
897F
TRCV_C: DATA parameter: Internal error (for example, invalid VARIANT reference).
1
8A3A
TRCV_C: DATA parameter: No access to the data area (for example because the data block
does not exist).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
847
Communication
11.2 PROFINET
Note
Error messages of the instructions TCON, TSEND, TRCV, and TDISCON
Internally, the TSEND_C instruction uses the TCON, TSEND, and TDISCON instructions;
and the TRCV_C instruction uses the TCON, TRCV, and TDISCON instructions. Refer to
"TCON, TDISCON, TSEND, AND TRCV (Page 857)" for more information on error
messages of these instructions.
Connection Ethernet protocols
Every CPU has an integrated PROFINET port, which supports standard PROFINET
communications. The TSEND_C and TRCV_C and TSEND and TRCV instructions all
support the TCP and ISO on TCP Ethernet protocols.
Refer to "Device Configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
11.2.8.8
Legacy TSEND_C and TRCV_C instructions
Prior to the release of STEP 7 V13 SP1 and the S7-1200 V4.1 CPUs, the TSEND_C and
TRCV_C instructions could only work with connection parameters with structures according
to "TCON_Param". The general concepts apply to both sets of instructions. Refer to the
individual legacy TSEND_C and TRCV_C instructions for programming information.
Selecting the version of the TSEND_C and TRCV_C instructions
There are two versions of the TSEND_C and TRCV_C instructions available in STEP 7:
● Versions 2.5 and 3.1 were available in STEP 7 Basic/Professional V13 or earlier.
● Version 4.0 is available in STEP 7 Basic/Professional V13 SP1 or later.
For compatibility and ease of migration, you can choose which instruction version to insert
into your user program.
Do not use different instruction versions in the same CPU program.
Click the icon on the instruction tree task card to enable the headers and columns
of the instruction tree.
To change the version of the TSEND_C and
TRCV_C instructions, select the version from
the drop-down list. You can select the group
or individual instructions.
S7-1200 Programmable controller
848
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
When you use the instruction tree to place a TSEND_C or TRCV_C instruction in your
program, a new FB or FC instance, depending on the TSEND_C or TRCV_C instruction
selected, is created in the project tree. You can see new FB or FC instance in the project
tree under PLC_x > Program blocks > System blocks > Program resources.
To verify the version of a TSEND_C or TRCV_C instruction in a program, you must inspect
project tree properties and not the properties of a box displayed in the program editor. Select
a project tree TSEND_C or TRCV_C FB or FC instance, right-click, select "Properties", and
select the "Information" page to see the TSEND_C or TRCV_C instruction version number.
Legacy TSEND_C and TRCV_C (Send and receive data using Ethernet)
The legacy TSEND_C instruction combines the functions of the legacy TCON, TDISCON
and TSEND instructions. The TRCV_C instruction combines the functions of the TCON,
TDISCON, and TRCV instructions. (Refer to "Legacy TCON, TDISCON, TSEND, and TRCV
(TCP communication) instructions (Page 868)" for more information on these instructions.)
The minimum size of data that you can transmit (TSEND_C) or receive (TRCV_C) is one
byte; the maximum size is 8192 bytes. TSEND_C does not support the transmission of data
from Boolean locations, and TRCV_C will not receive data into Boolean locations. For
information on transferring data with these instructions, see the section on data consistency
(Page 198).
Note
Initializing the communication parameters
After you insert the TSEND_C or TRCV_C instruction, use the "Properties" of the instruction
(Page 807) to configure the communication parameters (Page 832). As you enter the
parameters for the communication partners in the inspector window, STEP 7 enters the
corresponding data in the DB for the instruction.
If you want to use a multi-instance DB, you must manually configure the DB on both CPUs.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
849
Communication
11.2 PROFINET
Table 11- 15 TSEND_C and TRCV_C instructions
LAD / FBD
1
SCL
"TSEND_C_DB"(
req:=_bool_in_,
cont:=_bool_in_,
len:=_uint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
connect:=_struct_inout_,
data:=_variant_inout_,
com_rst:=_bool_inout_);
"TRCV_C_DB"(
en_r:=_bool_in_,
cont:=_bool_in_,
len:=_uint_in_,
adhoc:=_bool_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
rcvd_len=>_uint_out_,
connect:=_struct_inout_,
data:=_variant_inout_,
com_rst:=_bool_inout_);
Description
TSEND_C establishes a TCP or ISO on TCP
communication connection to a partner station,
sends data, and can terminate the connection.
After the connection is set up and established, it
is automatically maintained and monitored by
the CPU.
TRCV_C establishes a TCP or ISO on TCP
communication connection to a partner CPU,
receives data, and can terminate the connection.
After the connection is set up and established, it
is automatically maintained and monitored by
the CPU.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
850
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 16 TSEND_C and TRCV_C data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
REQ = 1 starts the TSEND_C send job on a rising edge with the
connection descricribed in CONNECT parameter. (CONT = 1 is
also required to establish and maintain the communication connection.
IN
Bool
When EN_R = 1, TRCV_C is ready to receive. The receive job is
processed. (CONT = 1 is also required to establish and maintain
the communication connection.)
IN
Bool
Controls the communication connection:
(TSEND_C)
EN_R
(TRCV_C)
CONT
•
0: Disconnect the communication connection
• 1: Establish and maintain the communication connection
When sending data (TSEND_C) (rising edge at the REQ parameter), the CONT parameter must have the value TRUE in
order to establish or maintain a connection.
When receiving data (TRCV_C) (rising edge at the EN_R parameter), the CONT parameter must have the value TRUE in
order to establish or maintain a connection.
LEN
IN
UInt
Maximum number of bytes to be sent (TSEND_C) or received
(TRCV_C):
•
Default = 0: The DATA parameter determines the length of
the data to be sent (TSEND_C) or received (TRCV_C).
•
Ad hoc mode = 65535: A variable length of data is set for
reception (TRCV_C).
CONNECT
IN_OUT
TCON_Param
Pointer to the connection description (Page 832)
DATA
IN_OUT
Variant
•
Contains address and length of data to be sent (TSEND_C)
•
Contains start address and maximum length of received data
(TRCV_C).
COM_RST
DONE
BUSY
ERROR
IN_OUT
OUT
OUT
OUT
Bool
Bool
Bool
Bool
Allows restart of the instruction:
•
0: Irrelevant
•
1: Complete restart of the function block, existing connection
will be terminated.
•
0: Job is not yet started or still running.
•
1: Job completed without error.
•
0: Job is completed.
•
1: Job is not yet completed. A new job cannot be triggered.
Status parameters with the following values:
•
0: No error
•
1: Error occurred during processing. STATUS provides detailed information on the type of error.
STATUS
OUT
Word
Status information including error information. (Refer to the
"Error and Status Parameters" table below.)
RCVD_LEN
OUT
Int
Amount of data actually received, in bytes
(TRCV_C)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
851
Communication
11.2 PROFINET
Note
The TSEND_C instruction requires a low-to-high transition at the REQ input parameter to
start a send job. The BUSY parameter is then set to 1 during processing. Completion of the
send job is indicated by either the DONE or ERROR parameters being set to 1 for one scan.
During this time, any low-to-high transition at the REQ input parameter is ignored.
Note
The default setting of the LEN parameter (LEN = 0) uses the DATA parameter to determine
the length of the data being transmitted. It is recommended that the data transmitted by the
TSEND_C instruction be the same size as the DATA parameter of the TRCV_C instruction.
If using the default setting of the LEN parameter and it is necessary to send the data in
segments smaller than the DATA parameter size, the following applies. If the size of the data
transmitted from TSEND_C does not equal the TRCV_C DATA parameter size, TRCV_C
remains in a busy status (status code: 7006) until the overall size of the data transmitted
from TSEND_C equals the TRCV_C DATA parameter size.
The TRCV_C DATA parameter buffer does not display the new data received until the data
size equals the DATA parameter buffer size.
TSEND_C operations
The following functions describe the operation of the TSEND_C instruction:
● To establish a connection, execute TSEND_C with CONT = 1.
● After successful establishing of the connection, TSEND_C sets the DONE parameter for
one cycle.
● To terminate the communication connection, execute TSEND_C with CONT = 0. The
connection will be aborted immediately. This also affects the receiving station. The
connection will be closed there and data inside the receive buffer could be lost.
● To send data over an established connection, execute TSEND_C with a rising edge on
REQ. After a successful send operation, TSEND_C sets the DONE parameter for one
cycle.
● To establish a connection and send data, execute TSEND_C with CONT =1 and REQ =
1. After a successful send operation, TSEND_C sets the DONE parameter for one cycle.
S7-1200 Programmable controller
852
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TRCV_C operations
The following functions describe the operation of the TRCV_C instruction:
● To establish a connection, execute TRCV_C with parameter CONT = 1.
● To receive data, execute TRCV_C with parameter EN_R = 1. TRCV_C receives the data
continuously when parameters EN_R = 1 and CONT = 1.
● To terminate the connection, execute TRCV_C with parameter CONT = 0. The
connection will be aborted immediately, and data could be lost.
TRCV_C handles the same receive modes as the TRCV instruction. The following table
shows how data is entered in the receive area:
Table 11- 17 Entering the data into the receive area
Protocol variant
Entering the data in the Parameter
receive area
"connection_type"
Value of the LEN parameter
Value of the RCVD_LEN
parameter (bytes)
TCP
Ad hoc mode
B#16#11
65535
1 to 1472
TCP
Data reception with
specified length
B#16#11
0 (recommended) or 1 to
8192, except 65535
1 to 8192
ISO on TCP
Ad hoc mode
B#16#12
65535
1 to 1472
ISO on TCP
Protocol-controlled
B#16#12
0 (recommended) or 1 to
8192, except 65535
1 to 8192
Note
Ad hoc mode
The "ad hoc mode" exists with the TCP and ISO on TCP protocol variants. You set "ad hoc
mode" by assigning "65535" to the LEN parameter. The receive area is identical to the area
formed by DATA. The length of the received data will be output to the parameter
RCVD_LEN.
If you store the data in an "optimized" DB (symbolic only), you can receive data only in
arrays of Byte, Char, USInt, and SInt data types.
Note
Importing of S7-300/400 STEP 7 projects containing "ad hoc mode" into the S7-1200
In S7-300/400 STEP 7 projects, "ad hoc mode" is selected by assigning "0" to the LEN
parameter. In the S7-1200, you set "ad hoc mode" by assigning "65535" to the LEN
parameter.
If you import an S7-300/400 STEP 7 project containing "ad hoc mode" into the S7-1200, you
must change the LEN parameter to "65535".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
853
Communication
11.2 PROFINET
Note
Must keep the data in the sender area consistent until the DONE parameter or the ERROR
parameter assumes the value TRUE
Due to the asynchronous processing of TSEND_C, you must keep the data in the sender
area consistent until the DONE parameter or the ERROR parameter assumes the value
TRUE.
For TSEND_C, a TRUE state at the parameter DONE means that the data was sent
successfully. It does not mean that the connection partner CPU actually read the receive
buffer.
Due to the asynchronous processing of TRCV_C, the data in the receiver area are only
consistent when parameter DONE = 1.
Table 11- 18 TSEND_C and TRCV_C instructions BUSY, DONE, and ERROR parameters
BUSY
DONE
ERROR
Description
TRUE
irrelevant
irrelevant
The job is being processed.
FALSE
TRUE
FALSE
The job is successfully completed.
FALSE
FALSE
TRUE
The job was ended with an error. The cause of the error can be found
in the STATUS parameter.
FALSE
FALSE
FALSE
A new job was not assigned.
TSEND_C and TRCV_C Error and Status condition codes
ERROR
STATUS
Description
0
0000
Job executed without error
0
7000
No job processing active
0
7001
Start job processing, establishing connection, waiting for connection partner
0
7002
Data being sent or received
0
7003
Connection being terminated
0
7004
Connection established and monitored, no job processing active
1
8085
LEN parameter is greater than the largest permitted value.
1
8086
The CONNECT parameter is outside the permitted range.
1
8087
Maximum number of connections reached; no additional connection possible.
1
8088
LEN parameter is not valid for the memory area specified in DATA.
1
8089
The CONNECT parameter does not point to a data block.
1
8091
Maximum nesting depth exceeded.
1
809A
The CONNECT parameter points to a field that does not match the length of the connection description.
1
809B
The local_device_id in the connection description does not match the CPU.
S7-1200 Programmable controller
854
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
ERROR
STATUS
Description
1
80A1
Communications error:
•
The specified connection was not yet established
•
The specified connection is currently being terminated; transmission over this connection is not possible
•
The interface is being reinitialized
1
80A3
Attempt being made to terminate a nonexistent connection
1
80A4
IP address of the remote partner connection is invalid. For example, the remote partner
IP address is the same as the local partner IP address.
1
80A5
Connection ID (Page 828) is already in use.
1
80A7
Communications error: You called TDISCON before TSEND_C was complete.
1
80B2
The CONNECT parameter points to a data block that was generated with the keyword
UNLINKED.
1
80B3
Inconsistent parameters:
1
80B4
•
Error in the connection description
•
Local port (parameter local_tsap_id) is already present in another connection description.
•
ID in the connection description different from the ID specified as parameter
When using the ISO on TCP (connection_type = B#16#12) to establish a passive connection, condition code 80B4 alerts you that the TSAP entered did not conform to one
of the following address requirements:
•
For a local TSAP length of 2 and a TSAP ID value of either E0 or E1 (hexadecimal)
for the first byte, the second byte must be either 00 or 01.
•
For a local TSAP length of 3 or greater and a TSAP ID value of either E0 or E1
(hexadecimal) for the first byte, the second byte must be either 00 or 01 and all other bytes must be valid ASCII characters.
For a local TSAP length of 3 or greater and the first byte of the TSAP ID does not
have a value of either E0 or E1 (hexadecimal), then all bytes of the TSAP ID must
be valid ASCII characters.
Valid ASCII characters are byte values from 20 to 7E (hexadecimal).
•
1
80B7
Data type and/or length of the transmitted data does not fit in the area in the partner
CPU in which it is to be written.
1
80C3
All connection resources are in use.
1
80C4
Temporary communications error:
•
The connection cannot be established at this time
•
The interface is receiving new parameters
•
The configured connection is currently being removed by a TDISCON.
1
8722
CONNECT parameter: Source area invalid: area does not exist in DB.
1
873A
CONNECT parameter: Access to connection description is not possible (for example,
DB not available)
1
877F
CONNECT parameter: Internal error such as an invalid ANY reference
1
893A
Parameter contains the number of a DB that is not loaded.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
855
Communication
11.2 PROFINET
Connection Ethernet protocols
Every CPU has an integrated PROFINET port, which supports standard PROFINET
communications. The TSEND_C and TRCV_C and TSEND and TRCV instructions all
support the TCP and ISO on TCP Ethernet protocols.
Refer to "Device Configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
11.2.8.9
TCON, TDISCON, TSEND, and TRCV instructions
As of version V4.1 of the S7-1200 CPU together with STEP 7 V13 SP1, the CPU extends the
capability of the TCON, TDISCON, TSEND, and TRCV instructions to use connection
parameters with structures according to "TCON_IP_v4" and "TCON_IP_RFC".
For this reason, the S7-1200 supports two sets of TCON, TDISCON, TSEND, and TRCV
instructions:
● Legacy TCON, TDISCON, TSEND, and TRCV instructions (Page 868): These TCON,
TDISCON, TSEND, and TRCV instructions existed prior to version V4.0 of the S7-1200
and only work with connection parameters with structures according to "TCON_Param".
● TCON, TDISCON, TSEND, and TRCV instructions (Page 857): These TCON, TDISCON,
TSEND, and TRCV instructions provide all of the functionality of the legacy instructions,
plus the ability to use connection parameters with structures according to "TCON_IP_v4"
and "TCON_IP_RFC".
Selecting the version of the TCON, TDISCON, TSEND, and TRCV instructions
There are two versions of the TCON, TDISCON, TSEND, or TRCV instructions available in
STEP 7:
● Versions 2.5 and 3.1 were available in STEP 7 Basic/Professional V13 or earlier.
● Version 4.0 is available in STEP 7 Basic/Professional V13 SP1 or later.
For compatibility and ease of migration, you can choose which instruction version to insert
into your user program.
Do not use different instruction versions in the same CPU program.
Click the icon on the instruction tree task card to enable the headers and columns
of the instruction tree.
To change the version of the TCON,
TDISCON, TSEND, or TRCV instructions,
select the version from the drop-down list.
You can select the group or individual instructions.
When you use the instruction tree to place a TCON, TDISCON, TSEND, or TRCV instruction
in your program, a new FB or FC instance, depending on the TCON, TDISCON, TSEND, or
TRCV instruction selected, is created in the project tree. You can see new FB or FC instance
in the project tree under PLC_x > Program blocks > System blocks > Program resources.
S7-1200 Programmable controller
856
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
To verify the version of a TCON, TDISCON, TSEND, or TRCV instruction in a program, you
must inspect project tree properties and not the properties of a box displayed in the program
editor. Select a project tree TCON, TDISCON, TSEND, or TRCV FB or FC instance, rightclick, select "Properties", and select the "Information" page to see the TCON, TDISCON,
TSEND, or TRCV instruction version number.
TCON, TDISCON, TSEND, and TRCV (TCP communication) instructions
Ethernet communication using TCP and ISO on TCP protocols
Note
TSEND_C and TRCV_C instructions
To help simplify the programming of PROFINET/Ethernet communication, the TSEND_C
instruction and the TRCV_C instruction combine the functionality of the TCON, TDISCON.
TSEND and TRCV instructions:
• TSEND_C combines the TCON, TDISCON and TSEND instructions.
• TRCV_C combines the TCON, TDISCON and TRCV instructions.
The following instructions control the communication process:
● TCON establishes the TCP/IP connection between the client and server (CPU) PC.
● TSEND and TRCV send and receive data.
● TDISCON breaks the connection.
The minimum size of data that you can transmit (TSEND) or receive (TRCV) is one byte; the
maximum size is 8192 bytes. TSEND does not support the transmission of data from
Boolean locations, and TRCV will not receive data into Boolean locations. For information
transferring data with these instructions, see the section on data consistency (Page 198).
TCON, TDISCON, TSEND, and TRCV operate asynchronously, which means that the job
processing extends over multiple instruction executions. For example, you start a job for
setting up and establishing a connection by executing an instruction TCON with parameter
REQ = 1. Then you use additional TCON executions to monitor the job progress and test for
job completion with parameter DONE.
The following table shows the relationships between BUSY, DONE, and ERROR. Use the
table to determine the current job status:
Table 11- 19 Interactions between the BUSY, DONE, and ERROR parameters
BUSY
DONE
ERROR
Description
1
0
0
The job is being processed.
0
1
0
The job successfully completed.
0
0
1
The job ended with an error. The cause of the error is output at the STATUS parameter.
0
0
0
No new job assigned.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
857
Communication
11.2 PROFINET
TCON and TDISCON
Note
Initializing the communication parameters
After you insert the TCON instruction, use the "Properties" of the instruction (Page 807) to
configure the communication parameters (Page 832). As you enter the parameters for the
communication partners in the inspector window, STEP 7 enters the corresponding data in
the instance DB for the instruction.
If you want to use a multi-instance DB, you must manually configure the DB on both CPUs.
Table 11- 20 TCON and TDISCON instructions
LAD / FBD
1
"TCON_DB"(
req:=_bool_in_,
ID:=_undef_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
connect:=_struct_inout_);
"TDISCON_DB"(
req:=_bool_in_,
ID:=_word_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_);
Description
TCP and ISO on TCP: TCON initiates a communications connection from the CPU to a communication partner.
TCP and ISO on TCP: TDISCON terminates a
communications connection from the CPU to a
communication partner.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
858
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 21 Data types for the parameters of TCON and TDISCON
Parameter
Declaration
Data type
Description
REQ
IN
Bool
Starts the job to establish the connection specified in the ID
upon a rising edge.
ID
IN
CONN_OUC (Word)
Reference to the assigned connection.
Range of values: W#16#0001 to W#16#0FFF
CONNECT
IN_OUT
VARIANT
(TCON)
Pointer to the connection description
•
For TCP or UDP, use the structure TCON_IP_v4
For further information on TCON_IP_v4, refer to: "Parameters for the PROFINET connection" (Page 832).
•
For ISO-on-TCP, use the structure TCON_IP_RFC
For further information on TCON_IP_RFC, refer to: "Parameters for the PROFINET connection" (Page 832).
DONE
BUSY
ERROR
STATUS
OUT
OUT
OUT
OUT
Bool
Bool
Bool
Word
Status parameter with the following values:
•
0: Job not yet started or still in progress
•
1: Job executed without errors
Status parameter with the following values:
•
0: Job not yet started or already completed
•
1: Job not yet completed. A new job cannot be started
Status parameter ERROR:
•
0: No error
•
1: Error occurred
Status of the instruction
Both communication partners execute the TCON instruction to set up and establish the
communication connection. You use parameters to specify the active and passive
communication end point partners. After the connection is set up and established, it is
automatically maintained and monitored by the CPU.
If the connection is terminated due to a line break or due to the remote communications
partner, for example, the active partner attempts to re-establish the configured connection.
You do not have to execute TCON again.
An existing connection is terminated and the set-up connection is removed when the
TDISCON instruction is executed or when the CPU has gone into STOP mode. To set up
and re-establish the connection, you must execute TCON again.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
859
Communication
11.2 PROFINET
Table 11- 22 ERROR and STATUS condition codes for TCON and TDISCON
ERROR
STATUS
(W#16#...)
Explanation
0
0000
Connection successfully established.
0
7000
No job processing active
0
7001
Start job execution; establish connection (TCON) or terminate connection (TDISCON).
0
7002
Connection is being established (REQ irrelevant); establish connection (TCON) or terminate
connection (TDISCON).
1
8085
TCON: Connection ID is already in use.
1
8086
TCON: The ID parameter is outside the valid range.
1
8087
TCON: Maximum number of connections reached; no additional connection possible
1
8089
TCON: The CONNECT parameter does not point to a connection description or the connection
description was created manually.
1
809A
TCON: The structure at the CONNECT parameter is not supported or the length is invalid.
1
809B
TCON: The ID of the local device in the connection description does not correspond to the
CPU or the CP, or it is "0".
1
80A0
Group error for error codes W#16#80A1 and W#16#80A2.
1
80A1
TCON: For TCP/UDP (TCON_IP_v4): Connection or port is already in use.
1
80A2
TCON: Local or remote port is being used by the system.
1
80A3
TCON: Value at the ID parameter is already being used by a connection (TCON) that was
created using the user program. The connection uses the identical ID, but different connection
settings at the parameter CONNECT.
1
80A4
TCON: IP address of the remote endpoint of the connection is invalid or it corresponds to the
IP address of the local partner.
1
80A5
TCON: Connection ID is already in use.
1
80A7
TCON: Communication error: You executed "TDISCON" before "TCON" had completed.
1
80B2
TCON: The CONNECT parameter points to a data block that was generated with the attribute
"Only store in load memory".
1
80B3
Inconsistent parameter assignment: Group error for error codes W#16#80A0 to W#16#80A2,
W#16#80A4, W#16#80B4 to W#16#80B9.
1
80B4
TCON: Only with TCON_IP_RFC The local T selector was not specified or the first byte does
not contain the value 0x0E or the local T selector starts with "SIMATIC-".
1
80B5
TCON: Only passive connection establishment is permitted for connection type 13 = UDP
(Parameter active_est of the structure TCON_IP_v4 has the value TRUE)..
1
80B6
TCON: Parameter assignment error in the connection_type parameter of the data block for
connection description.
•
Only valid with TCON_IP_v4: 0x11, 0x0B and 0x13.
•
Only valid with TCON_IP_RFC: 0x0C and 0x12
S7-1200 Programmable controller
860
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
ERROR
STATUS
(W#16#...)
Explanation
1
80B7
TCON: With TCON_IP_v4:
•
TCP (active connection establishment): Remote port is "0".
•
TCP (passive connection establishment): Local port is "0".
• UDP: Local port is "0".
TCON: With TCON_IP_RFC:
•
Local (local_tselector) or remote (remote_tselector) T selector was specified with a length
of more than 32 bytes.
•
For TSelLength of the T selector (local or remote), a length greater than 32 was entered.
•
Error in the length of the IP address of the specific connection partner.
1
80B8
TCON: Parameter ID in the local connection description (structure at parameter CONNECT)
and parameter ID of the instruction are different.
1
80C3
TCON: All connection (Page 828) resources are in use.
1
80C4
Temporary communication error:
•
The connection cannot be established at this time (TCON).
•
The interface is currently receiving new parameters (TCON and TDISCON).
•
The configured connection is currently being removed by a "TDISCON" instruction (TCON).
1
80C5
TCON: The remote partner refuses to establish the connection, has terminated the connection
or actively ended it.
1
80C6
TCON: The remote partner cannot be reached (network error).
1
80C7
TCON: Execution timeout.
1
80C8
TCON: ID is used by a connection created by the user program, which uses the same connection description at the CONNECT parameter.
1
80C9
TCON: Validation of the remote partner failed. The remote partner that wants to establish the
connection does not match the defined partner of the structure at the CONNECT parameter.
1
80CE
TCON: The IP address of the local interface is 0.0.0.0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
861
Communication
11.2 PROFINET
TSEND and TRCV
Note
When using PROFINET Open User communication, if you execute a TSEND instruction
without a corresponding TRCV instruction executing on the remote device, then the TSEND
instruction may reside indefinitely in a "Busy State", waiting for the TRCV instruction to
receive the data. In this state, the TSEND instruction "Busy" output is set, and the "Status"
output has a value of "0x7002". This condition may occur if you are transferring more than
4096 bytes of data. The issue is resolved at the next execution of the TRCV instruction.
Table 11- 23 TSEND and TRCV instructions
LAD / FBD
1
SCL
"TSEND_DB"(
req:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
data:=_variant_inout_);
"TRCV_DB"(
en_r:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
adhoc:=_bool_in_,
ndr=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
rcvd_len=>_udint_out_,
data:=_variant_inout_);
Description
TCP and ISO on TCP: TSEND sends data
through a communication connection from the
CPU to a partner station.
TCP and ISO on TCP: TRCV receives data
through a communication connection from a
partner station to the CPU.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
862
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 24 Data types for the parameters of TSEND and TRCV
Parameter and type
Data type
Description
REQ
IN
Bool
TSEND: Starts the send job on a rising edge. The data is transferred from the area specified by DATA and LEN.
EN_R
IN
Bool
TRCV: Enables the CPU to receive; with EN_R = 1, the TRCV is
ready to receive. The receive job is processed.
ID
IN
CONN_OUC
(Word)
Reference to the associated connection. ID must be identical to
the associated parameter ID in the local connection description.
Value range: W#16#0001 to W#16#0FFF
LEN
ADHOC
IN
IN
UDInt
Bool
Maximum number of bytes to be sent (TSEND) or received
(TRCV):
•
Default = 0: The DATA parameter determines the length of the
data to be sent (TSEND) or received (TRCV).
•
Ad hoc mode = 65535: A variable length of data is set for reception (TRCV).
TRCV: Optional parameter (hidden)
Ad hoc mode request for connection type TCP.
DATA
IN_OUT
Variant
Pointer to send (TSEND) or receive (TRCV) data area; data area
contains the address and length. The address refers to I memory,
Q memory, M memory, or a DB.
DONE
OUT
Bool
TSEND:
NDR
BUSY
OUT
OUT
Bool
Bool
•
0: Job not yet started or still running.
•
1: Job executed without error.
TRCV:
•
NDR = 0: Job not yet started or still running.
•
NDR = 1: Job successfully completed.
•
BUSY = 1: The job is not yet complete. A new job cannot be
triggered.
•
BUSY = 0: Job is complete.
ERROR
OUT
Bool
ERROR = 1: Error occurred during processing. STATUS provides
detailed information on the type of error
STATUS
OUT
Word
Status information including error information. (Refer to the Error
and Status condition codes in the table below.)
RCVD_LEN
OUT
UDInt
TRCV: Amount of data actually received in bytes
Note
The TSEND instruction requires a low-to-high transition at the REQ input parameter to start
a send job. The BUSY parameter is then set to 1 during processing. Completion of the send
job is indicated by either the DONE or ERROR parameters being set to 1 for one scan.
During this time, any low-to-high transition at the REQ input parameter is ignored.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
863
Communication
11.2 PROFINET
TRCV Operations
The TRCV instruction writes the received data to a receive area that is specified by the
following two variables:
● Pointer to the start of the area
● Length of the area or the value supplied at the LEN input if not 0
Note
The default setting of the LEN parameter (LEN = 0) uses the DATA parameter to
determine the length of the data being transmitted. It is recommended that the data
transmitted by the TSEND instruction be the same size as the DATA parameter of the
TRCV instruction.
If using the default setting of the LEN parameter and it is necessary to send the data in
segments smaller than the DATA parameter size, the following applies. It is
recommended to keep the EN_R bit high until the corresponding TSEND transfers the
appropriate amount of data to fill the TRCV DATA parameter. If the size of the data
transmitted from TSEND does not equal the TRCV DATA parameter size, TRCV remains
in a busy status (status code: 7002) while the EN_R bit is high until the overall size of the
data transmitted from TSEND equals the TRCV DATA parameter size. If the EN_R bit of
TRCV is pulsed, it needs to be pulsed the same number of times as TSEND is executed
to receive the data.
The TRCV DATA parameter buffer does not display the new data received until the data
size equals the DATA parameter buffer size.
As soon as all the job data has been received, TRCV transfers it to the receive area and sets
NDR to 1.
Table 11- 25 Entering the data into the receive area
Protocol variant
Entering the data in the Parameter
receive area
"connection_type"
Value of the LEN parameter
Value of the RCVD_LEN
parameter (bytes)
TCP
Ad hoc mode
B#16#11
Selected with the TRCV instruction ADHOC input
1 to 1472
TCP
Data reception with
specified length
B#16#11
0 (recommended) or 1 to
8192, except 65535
1 to 8192
ISO on TCP
Ad hoc mode
B#16#12
65535
1 to 1472
ISO on TCP
protocol-controlled
B#16#12
0 (recommended) or 1 to
8192, except 65535
1 to 8192
S7-1200 Programmable controller
864
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Note
Ad hoc mode
The "ad hoc mode" exists with the TCP and ISO on TCP protocol variants. To configure the
TRCV instruction for ad hoc mode, set the ADHOC instruction input parameter. The receive
area is identical to the area formed by DATA. The length of the received data will be output
to the parameter RCVD_LEN. Immediately after receiving a block of data, TRCV enters the
data in the receive area and sets NDR to 1.
If you store the data in an "optimized" DB (symbolic only), you can receive data only in
arrays of Byte, Char, USInt, and SInt data types.
Note
Importing of S7-300/400 STEP 7 projects containing "ad hoc mode" into the S7-1200
In S7-300/400 STEP 7 projects, "ad hoc mode" is selected by assigning "0" to the LEN
parameter. In the S7-1200, you configure the TRCV instruction for ad hoc mode by setting
the ADHOC instruction input parameter.
If you import an S7-300/400 STEP 7 project containing "ad hoc mode" into the S7-1200, you
must change the LEN parameter to "65535".
Table 11- 26 ERROR and STATUS condition codes for TSEND and TRCV
ERROR
STATUS
0
0000
0
0
0
1
7000
7001
7002
8085
Description
•
Send job completed without error (TSEND)
•
New data accepted: The current length of the received data is shown in RCVD_LEN
(TRCV).
•
No job processing active (TSEND)
•
Block not ready to receive (TRCV)
•
Start of job processing, data being sent: During this processing the operating system accesses the data in the DATA send area (TSEND).
•
Block is ready to receive, receive job was activated (TRCV).
•
Follow-on instruction execution (REQ irrelevant), job being processed: The operating system accesses the data in the DATA send area during this processing
(TSEND).
•
Follow-on instruction execution, receive job being processed: Data is written to the
receive area during this processing. For this reason, an error could result in inconsistent data in the receive area (TRCV).
•
LEN parameter is greater than the largest permitted value (TSEND) and (TRCV).
•
LEN or DATA parameter changed since the first instruction execution (TRCV).
1
8086
The ID parameter is not in the permitted address range.
1
8088
The LEN parameter is larger than the memory area specified in DATA.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
865
Communication
11.2 PROFINET
ERROR
STATUS
Description
1
80A1
Communications error:
•
The specified connection has not yet established (TSEND and TRCV).
•
The specified connection is currently being terminated. Transmission or a receive
job over this connection is not possible (TSEND and TRCV).
•
The interface is being reinitialized (TSEND).
•
The interface is receiving new parameters (TRCV).
1
80C3
Internal lack of connection (Page 828) resources: A block with this ID is already being
processed in a different priority class.
1
80C4
Temporary communications error:
•
The connection to the communications partner cannot be established at this time.
•
The interface is receiving new parameter settings, or the connection is currently
being established.
Connection Ethernet protocols
Every CPU has an integrated PROFINET port, which supports standard PROFINET
communications. The TSEND_C, TRCV_C, TSEND and TRCV instructions all support the
TCP and ISO on TCP Ethernet protocols.
Refer to "Device Configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
S7-1200 Programmable controller
866
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8.10
Legacy TCON, TDISCON, TSEND, and TRCV instructions
Prior to the release of STEP 7 V13 SP1 and the S7-1200 V4.1 CPUs, the TCON, TDISCON,
TSEND, and TRCV instructions could only work with connection parameters with structures
according to "TCON_Param". The general concepts apply to both sets of instructions. Refer
to the individual legacy TCON, TDISCON, TSEND, and TRCV instructions for programming
information.
Selecting the version of the TCON, TDISCON, TSEND, and TRCV instructions
There are two versions of the TCON, TDISCON, TSEND, or TRCV instructions available in
STEP 7:
● Versions 2.5 and 3.1 were available in STEP 7 Basic/Professional V13 or earlier.
● Version 4.0 is available in STEP 7 Basic/Professional V13 SP1 or later.
For compatibility and ease of migration, you can choose which instruction version to insert
into your user program.
Do not use different instruction versions in the same CPU program.
Click the icon on the instruction tree task card to enable the headers and columns
of the instruction tree.
To change the version of the TCON,
TDISCON, TSEND, or TRCV instructions,
select the version from the drop-down list.
You can select the group or individual instructions.
When you use the instruction tree to place a TCON, TDISCON, TSEND, or TRCV instruction
in your program, a new FB or FC instance, depending on the TCON, TDISCON, TSEND, or
TRCV instruction selected, is created in the project tree. You can see new FB or FC instance
in the project tree under PLC_x > Program blocks > System blocks > Program resources.
To verify the version of a TCON, TDISCON, TSEND, or TRCV instruction in a program, you
must inspect project tree properties and not the properties of a box displayed in the program
editor. Select a project tree TCON, TDISCON, TSEND, or TRCV FB or FC instance, rightclick, select "Properties", and select the "Information" page to see the TCON, TDISCON,
TSEND, or TRCV instruction version number.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
867
Communication
11.2 PROFINET
Legacy TCON, TDISCON, TSEND, and TRCV (TCP communication) instructions
Ethernet communication using TCP and ISO on TCP protocols
Note
TSEND_C and TRCV_C instructions
To help simplify the programming of PROFINET/Ethernet communication, the TSEND_C
instruction and the TRCV_C instruction combine the functionality of the TCON, TDISCON.
TSEND and TRCV instructions:
• TSEND_C combines the TCON, TDISCON and TSEND instructions.
• TRCV_C combines the TCON, TDISCON and TRCV instructions.
The following instructions control the communication process:
● TCON establishes the TCP/IP connection between the client and server (CPU) PC.
● TSEND and TRCV send and receive data.
● TDISCON breaks the connection.
The minimum size of data that you can transmit (TSEND) or receive (TRCV) is one byte; the
maximum size is 8192 bytes. TSEND does not support the transmission of data from
Boolean locations, and TRCV will not receive data into Boolean locations. For information
transferring data with these instructions, see the section on data consistency (Page 198).
TCON, TDISCON, TSEND, and TRCV operate asynchronously, which means that the job
processing extends over multiple instruction executions. For example, you start a job for
setting up and establishing a connection by executing an instruction TCON with parameter
REQ = 1. Then you use additional TCON executions to monitor the job progress and test for
job completion with parameter DONE.
The following table shows the relationships between BUSY, DONE, and ERROR. Use the
table to determine the current job status:
Table 11- 27 Interactions between the BUSY, DONE, and ERROR parameters
BUSY
DONE
ERROR
Description
TRUE
irrelevant
irrelevant
The job is being processed.
FALSE
TRUE
FALSE
The job successfully completed.
FALSE
FALSE
TRUE
The job was ended with an error. The cause of the error can be found in the
STATUS parameter.
FALSE
FALSE
FALSE
A new job was not assigned.
S7-1200 Programmable controller
868
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TCON and TDISCON
Note
Initializing the communication parameters
After you insert the TCON instruction, use the "Properties" of the instruction (Page 807) to
configure the communication parameters (Page 832). As you enter the parameters for the
communication partners in the inspector window, STEP 7 enters the corresponding data in
the instance DB for the instruction.
If you want to use a multi-instance DB, you must manually configure the DB on both CPUs.
Table 11- 28 TCON and TDISCON instructions
LAD / FBD
1
"TCON_DB"(
req:=_bool_in_,
ID:=_undef_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
connect:=_struct_inout_);
"TDISCON_DB"(
req:=_bool_in_,
ID:=_word_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_);
Description
TCP and ISO on TCP: TCON initiates a communications connection from the CPU to a communication partner.
TCP and ISO on TCP: TDISCON terminates a
communications connection from the CPU to a
communication partner.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
869
Communication
11.2 PROFINET
Table 11- 29 Data types for the parameters of TCON and TDISCON
Parameter and type
Data type
Description
REQ
IN
Bool
Control parameter REQ starts the job by establishing the
connection specified by ID. The job starts at rising edge.
ID
IN
CONN_OUC (Word)
Reference to the connection to be established (TCON) or
terminated (TDISCON) to the remote partner, or between
the user program and the communication layer of the operating system. The ID must be identical to the associated
parameter ID in the local connection description.
Value range: W#16#0001 to W#16#0FFF
CONNECT
IN_OUT
TCON_Param
Pointer to the connection description (Page 832)
OUT
Bool
•
0: Job is not yet started or still running.
•
1: Job completed without error.
•
0: Job is completed.
•
1: Job is not yet completed. A new job cannot be triggered.
(TCON)
DONE
BUSY
ERROR
STATUS
OUT
OUT
OUT
Bool
Bool
Word
Status parameters with the following values:
•
0: No error
•
1: Error occurred during processing. STATUS provides
detailed information on the type of error.
Status information including error information. (Refer to the
Error and Status condition codes in the table below.)
Both communication partners execute the TCON instruction to set up and establish the
communication connection. You use parameters to specify the active and passive
communication end point partners. After the connection is set up and established, it is
automatically maintained and monitored by the CPU.
If the connection is terminated due to a line break or due to the remote communications
partner, for example, the active partner attempts to re-establish the configured connection.
You do not have to execute TCON again.
An existing connection is terminated and the set-up connection is removed when the
TDISCON instruction is executed or when the CPU has gone into STOP mode. To set up
and re-establish the connection, you must execute TCON again.
S7-1200 Programmable controller
870
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 30 ERROR and STATUS condition codes for TCON and TDISCON
ERROR
STATUS
Description
0
0000
Connection was established successfully.
0
7000
No job processing active
0
7001
Start job processing; establishing connection (TCON) or terminating connection
(TDISCON)
0
7002
Follow-on call (REQ irrelevant); establishing connection (TCON) or terminating connection (TDISCON)
1
8086
The ID parameter is outside the permitted address range.
1
8087
TCON: Maximum number of connections reached; no additional connection possible.
1
809B
TCON: The local_device_id in the connection description does not match the CPU.
1
80A1
TCON: Connection or port is already occupied by user.
1
80A2
TCON: Local or remote port is occupied by the system.
1
80A3
Attempt being made to re-establish an existing connection (TCON) or terminate a nonexistent connection (TDISCON).
1
80A4
TCON: IP address of the remote connection end point is invalid; it matches the local
partner IP address.
1
80A5
TCON: Connection ID (Page 828) is already in use.
1
80A7
TCON: Communications error: You executed a TDISCON before the TCON completed.The TDISCON must first completely terminate the connection referenced by the ID.
1
80B2
TCON: The CONNECT parameter points to a data block that was generated with the
attribute "Only store in load memory".
1
80B4
TCON: When using the ISO on TCP (connection_type = B#16#12) to establish a passive connection, condition code 80B4 alerts you that the TSAP entered did not conform
to one of the following address requirements:
•
For a local TSAP length of 2 and a TSAP ID value of either E0 or E1 (hexadecimal)
for the first byte, the second byte must be either 00 or 01.
•
For a local TSAP length of 3 or greater and a TSAP ID value of either E0 or E1
(hexadecimal) for the first byte, the second byte must be either 00 or 01 and all other bytes must be valid ASCII characters.
For a local TSAP length of 3 or greater and the first byte of the TSAP ID does not
have a value of either E0 or E1 (hexadecimal), then all bytes of the TSAP ID must
be valid ASCII characters.
Valid ASCII characters are byte values from 20 to 7E (hexadecimal).
•
1
80B5
TCON: Connection type "13 = UDP" permits only passive connection establishment.
1
80B6
TCON: Parameter assignment error in CONNECTION_TYPE parameter of the SDT
TCON_Param.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
871
Communication
11.2 PROFINET
ERROR
STATUS
Description
1
80B7
TCON: Error in one of the following parameters of the data block for connection description:
•
block_length
•
local_tsap_id_len
•
rem_subnet_id_len
•
rem_staddr_len
•
rem_tsap_id_len
• next_staddr_len
Note: When operating TCON in TCP passive mode, the LOCAL_TSAP_ID_LEN must
be "2" and the REM_TSAP_ID_LEN must be "0".
1
80B8
TCON: Parameter in the local connection description and Parameter ID are different.
1
80C3
TCON: All connection resources are in use.
1
80C4
Temporary communications error:
•
The connection cannot be established at this time (TCON).
•
The configured connection is currently being removed by TDISCON (TCON).
•
The connection is currently being established (TDISCON).
•
The interface is receiving new parameters (TCON and TDISCON).
S7-1200 Programmable controller
872
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TSEND and TRCV
Note
When using PROFINET Open User communication, if you execute a TSEND instruction
without a corresponding TRCV instruction executing on the remote device, then the TSEND
instruction may reside indefinitely in a "Busy State", waiting for the TRCV instruction to
receive the data. In this state, the TSEND instruction "Busy" output is set, and the "Status"
output has a value of "0x7002". This condition may occur if you are transferring more than
4096 bytes of data. The issue is resolved at the next execution of the TRCV instruction.
Table 11- 31 TSEND and TRCV instructions
LAD / FBD
1
SCL
"TSEND_DB"(
req:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
data:=_variant_inout_);
"TRCV_DB"(
en_r:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
ndr=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
rcvd_len=>_udint_out_,
data:=_variant_inout_);
Description
TCP and ISO on TCP: TSEND sends data
through a communication connection from the
CPU to a partner station.
TCP and ISO on TCP: TRCV receives data
through a communication connection from a
partner station to the CPU.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
873
Communication
11.2 PROFINET
Table 11- 32 Data types for the parameters of TSEND and TRCV
Parameter and type
Data type
Description
REQ
IN
Bool
TSEND: Starts the send job on a rising edge. The data is transferred from the area specified by DATA and LEN.
EN_R
IN
Bool
TRCV: Enables the CPU to receive; with EN_R = 1, the TRCV is
ready to receive. The receive job is processed.
ID
IN
CONN_OUC
(Word)
Reference to the associated connection. ID must be identical to
the associated parameter ID in the local connection description.
Value range: W#16#0001 to W#16#0FFF
LEN
IN
UInt
Maximum number of bytes to be sent (TSEND) or received
(TRCV):
•
Default = 0: The DATA parameter determines the length of the
data to be sent (TSEND) or received (TRCV).
•
Ad hoc mode = 65535: A variable length of data is set for reception (TRCV).
DATA
IN_OUT
Variant
Pointer to send (TSEND) or receive (TRCV) data area; data area
contains the address and length. The address refers to I memory,
Q memory, M memory, or a DB.
DONE
OUT
Bool
TSEND:
NDR
BUSY
OUT
OUT
Bool
Bool
•
0: Job not yet started or still running.
•
1: Job executed without error.
TRCV:
•
NDR = 0: Job not yet started or still running.
•
NDR = 1: Job successfully completed.
•
BUSY = 1: The job is not yet complete. A new job cannot be
triggered.
•
BUSY = 0: Job is complete.
ERROR
OUT
Bool
ERROR = 1: Error occurred during processing. STATUS provides
detailed information on the type of error
STATUS
OUT
Word
Status information including error information. (Refer to the Error
and Status condition codes in the table below.)
RCVD_LEN
OUT
Int
TRCV: Amount of data actually received in bytes
Note
The TSEND instruction requires a low-to-high transition at the REQ input parameter to start
a send job. The BUSY parameter is then set to 1 during processing. Completion of the send
job is indicated by either the DONE or ERROR parameters being set to 1 for one scan.
During this time, any low-to-high transition at the REQ input parameter is ignored.
S7-1200 Programmable controller
874
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TRCV Operations
The TRCV instruction writes the received data to a receive area that is specified by the
following two variables:
● Pointer to the start of the area
● Length of the area or the value supplied at the LEN input if not 0
Note
The default setting of the LEN parameter (LEN = 0) uses the DATA parameter to
determine the length of the data being transmitted. It is recommended that the data
transmitted by the TSEND instruction be the same size as the DATA parameter of the
TRCV instruction.
If using the default setting of the LEN parameter and it is necessary to send the data in
segments smaller than the DATA parameter size, the following applies. It is
recommended to keep the EN_R bit high until the corresponding TSEND transfers the
appropriate amount of data to fill the TRCV DATA parameter. If the size of the data
transmitted from TSEND does not equal the TRCV DATA parameter size, TRCV remains
in a busy status (status code: 7002) while the EN_R bit is high until the overall size of the
data transmitted from TSEND equals the TRCV DATA parameter size. If the EN_R bit of
TRCV is pulsed, it needs to be pulsed the same number of times as TSEND is executed
to receive the data.
The TRCV DATA parameter buffer does not display the new data received until the data
size equals the DATA parameter buffer size.
As soon as all the job data has been received, TRCV transfers it to the receive area and sets
NDR to 1.
Table 11- 33 Entering the data into the receive area
Protocol variant
Entering the data in the Parameter
receive area
"connection_type"
Value of the LEN parameter
Value of the RCVD_LEN
parameter (bytes)
TCP
Ad hoc mode
B#16#11
65535
1 to 1472
TCP
Data reception with
specified length
B#16#11
0 (recommended) or 1 to
8192, except 65535
1 to 8192
ISO on TCP
Ad hoc mode
B#16#12
65535
1 to 1472
ISO on TCP
protocol-controlled
B#16#12
0 (recommended) or 1 to
8192, except 65535
1 to 8192
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
875
Communication
11.2 PROFINET
Note
Ad hoc mode
The "ad hoc mode" exists with the TCP and ISO on TCP protocol variants. You set "ad hoc
mode" by assigning "65535" to the LEN parameter. The receive area is identical to the area
formed by DATA. The length of the received data will be output to the parameter
RCVD_LEN. Immediately after receiving a block of data, TRCV enters the data in the receive
area and sets NDR to 1.
If you store the data in an "optimized" DB (symbolic only), you can receive data only in
arrays of Byte, Char, USInt, and SInt data types.
Note
Importing of S7-300/400 STEP 7 projects containing "ad hoc mode" into the S7-1200
In S7-300/400 STEP 7 projects, "ad hoc mode" is selected by assigning "0" to the LEN
parameter. In the S7-1200, you set "ad hoc mode" by assigning "65535" to the LEN
parameter.
If you import an S7-300/400 STEP 7 project containing "ad hoc mode" into the S7-1200, you
must change the LEN parameter to "65535".
TSEND and TRCV Error and Status condition codes
ERROR
STATUS
Description
0
0000
•
Send job completed without error (TSEND)
•
New data accepted: The current length of the received data is shown in RCVD_LEN
(TRCV).
•
No job processing active (TSEND)
•
Block not ready to receive (TRCV)
•
Start of job processing, data being sent: During this processing the operating system accesses the data in the DATA send area (TSEND).
•
Block is ready to receive, receive job was activated (TRCV).
•
Follow-on instruction execution (REQ irrelevant), job being processed: The operating system accesses the data in the DATA send area during this processing
(TSEND).
•
Follow-on instruction execution, receive job being processed: Data is written to the
receive area during this processing. For this reason, an error could result in inconsistent data in the receive area (TRCV).
•
LEN parameter is greater than the largest permitted value (TSEND) and (TRCV).
•
LEN or DATA parameter changed since the first instruction execution (TRCV).
0
0
0
1
7000
7001
7002
8085
1
8086
The ID parameter is not in the permitted address range.
1
8088
The LEN parameter is larger than the memory area specified in DATA.
S7-1200 Programmable controller
876
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
ERROR
STATUS
Description
1
80A1
Communications error:
•
The specified connection has not yet established (TSEND and TRCV).
•
The specified connection is currently being terminated. Transmission or a receive
job over this connection is not possible (TSEND and TRCV).
•
The interface is being reinitialized (TSEND).
•
The interface is receiving new parameters (TRCV).
1
80C3
Internal lack of resources: A block with this ID is already being processed in a different
priority class.
1
80C4
Temporary communications error:
•
The connection to the communications partner cannot be established at this time.
•
The interface is receiving new parameter settings, or the connection is currently
being established.
Connection Ethernet protocols
Every CPU has an integrated PROFINET port, which supports standard PROFINET
communications. The TSEND_C, TRCV_C, TSEND and TRCV instructions all support the
TCP and ISO on TCP Ethernet protocols.
Refer to "Device Configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
877
Communication
11.2 PROFINET
11.2.8.11
T_RESET (Terminate and re-establish an existing connection) instruction
The "T_RESET" instruction terminates and then re-establishes an existing connection:
Table 11- 34 T_RESET instruction
LAD / FBD
SCL
"T_RESET_DB"(
req:=_bool_in_,
id:=_word_in_,
done=>_bool_out_,
error=>_bool_out_,
status=>_word_out_);
Description
Use the T_RESET instruction to terminate and
then re-establish an existing connection.
The local end points of the connection are retained. They are generated automatically:
● If a connection has been configured and loaded to the CPU.
● If a connection has been generated by the user program, for example, by calling the
instruction "TCON (Page 857)".
The "T_RESET" instruction can be executed for all connection types regardless of whether
the local interface of the CPU or the interface of a CM/CP was used for the connection. An
exception to this is connections for data transfer in ad-hoc mode with TCP, as such
connections cannot be referenced with a connection ID.
Once the instruction "T_RESET" has been called using the REQ parameter, the connection
specified with the ID parameter is terminated and, if necessary, the data send and receive
buffer cleared. Canceling the connection also cancels any data transfer in progress. There is
therefore a risk of losing data if data transfer is in progress. The CPU defined as the active
connection partner will then automatically attempt to restore the interrupted communication
connection. You therefore do not need to call the "TCON (Page 857)" instruction to reestablish the communication connection.
The output parameters DONE, BUSY, and STATUS indicate the status of the job.
S7-1200 Programmable controller
878
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Data types for the parameters
The following table shows the parameters of the "T_RESET" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, D, L, T, C or
constant
Control parameter REQUEST starts the job
for terminating the connection specified by ID.
The job starts on a rising edge.
ID
Input
CONN_OUC
(WORD)
L, D or constant
Reference to the connection to the passive
partner which is to be terminated. ID must be
identical to the corresponding parameter ID in
the local connection description.
Range of values: W#16#0001 to W#16#0FFF
DONE
BUSY
ERROR
STATUS
Output
BOOL
Output
BOOL
Output
BOOL
Output
WORD
I, Q, M, D, L
I, Q, M, D, L
I, Q, M, D, L
I, Q, M, D, L
Status parameter DONE
•
0: Job not yet started or still executing.
•
1: Job executed without errors.
Status parameter BUSY
•
0: Job is complete.
•
1: Job is not yet complete.
Status parameter ERROR
•
0: No error occurred.
•
1: Error occurred during processing. The
STATUS parameter supplies detailed information on the type of error
Status parameter STATUS
Error information (see "STATUS parameter"
table).
STATUS parameter
Error bit
STATUS* Description
(W#16#...)
0
0000
No error.
0
0001
Connection has not been established.
0
7001
Connection termination launched.
0
7002
Connection being terminated.
1
8081
Unknown connection specified at the ID parameter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
879
Communication
11.2 PROFINET
11.2.8.12
T_DIAG (Checks the status of connection and reads information) instruction
The "T_DIAG" instruction checks the status of a connection and reads further information on
the local end point of this connection:
Table 11- 35 T_DIAG instruction
LAD / FBD
SCL
"T_DIAG_DB"(
req:=_bool_in_,
id:=_word_in_,
done=>_bool_out_,
error=>_bool_out_,
status=>_dword_out_);
Description
Use the T_DIAG instruction to check the status of a
connection and read further information on the
local end point of this connection.
The "T_DIAG" instruction operates as follows:
● The connection is referenced by the ID parameter. You can read both connection end
points configured in the connection editor and programmed connection end points (e.g.
with the "TCON" instruction).
Temporary connection end points (for example end points created when you connect to
an engineering station) cannot be diagnosed, as no connection ID is generated in this
process.
● The connection information read is stored in a structure referenced by the RESULT
parameter.
● The output parameter STATUS indicates whether it was possible to read the connection
information. The connection information in the structure at the RESULT parameter is only
valid if the "T_DIAG" instruction has been completed with STATUS = W#16#0000 and
ERROR = FALSE.
Connection information cannot be evaluated if an error occurs.
Possible connection information
The "TDiag_Status" structure can be used to read the connection information at the RESULT
parameter. The TDiag_Status structure only contains the most important information about a
connection end point (for example, the protocol used, the connection status, and the number
of data bytes sent or received).
The structure and parameters of the TDiag_Status structure are described below (see the
"TDIAG_Status structure" table).
S7-1200 Programmable controller
880
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Data types for the parameters
The following table shows the parameters of the "T_DIAG" instruction:
Parameter
Declaration
Data type
Memory area
Description
REQ
Input
BOOL
I, Q, M, D, L, T, C or
constant
Starts the instruction to check the connection
specified in the ID parameter when there is a
positive edge.
ID
Input
CONN_OUC
(WORD)
L, D or constant
Reference to the assigned connection.
Range of values: W#16#0001 to W#16#0FFF
RESULT
InOut
VARIANT
D
Pointer to the structure in which the connection information is stored. The structure TDiag_Status can be used at the RESULT
parameter (for a description, see the
"TDIAG_Status structure" table).
DONE
Output
BOOL
I, Q, M, D, L
Status parameter:
BUSY
Output
ERROR
BOOL
Output
STATUS
BOOL
Output
WORD
I, Q, M, D, L
I, Q, M, D, L
I, Q, M, D, L
•
0: Instruction not yet started or still in progress.
•
1: Instruction executed without errors.
Status parameter:
•
0: Instruction not yet started or already
completed.
•
1: Instruction not yet completed. A new job
cannot be started.
Status parameter:
•
0: No error.
•
1: Error occurred.
Status of the instruction
Parameters BUSY, DONE, and ERROR
You can check the status of "T_DIAG" instruction execution with the BUSY, DONE, ERROR
and STATUS parameters. The BUSY parameter indicates the processing status. You use
the DONE parameter to check whether or not an instruction has been executed successfully.
The ERROR parameter is set if errors occur during execution of "T_DIAG".
The following table shows the relationship between the BUSY, DONE, and ERROR
parameters:
BUSY
DONE
ERROR
Description
1
-
-
The instruction is being processed.
0
1
0
The instruction has been executed successfully. The data in the structure referenced by
RESULT are only valid if this is the case.
0
0
1
Instruction completed with an error. The cause of the error is output at the STATUS parameter.
0
0
0
No new instruction has been assigned.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
881
Communication
11.2 PROFINET
STATUS parameter
The following table shows the meaning of the values at the STATUS parameter:
Error bit
STATUS* Description
(W#16#...)
0
0000
The instruction "T_DIAG" has been executed successfully. The data in the structure referenced at
the RESULT parameter can be evaluated.
0
7000
No instruction processing active.
0
7001
Instruction processing launched.
0
7002
Connection information is being read (REQ parameter irrelevant).
1
8086
The value at the ID parameter is outside the valid range (W#16#0001 ... W#16#0FFF).
1
8089
The RESULT parameter points to an invalid data type (structures TDIAG_Status and
TDIAG_StatusExt only).
1
80A3
The ID parameter references a connection end point which does not exist. With programmed
connections, this error can also occur after the "TDISCON" instruction is called.
1
80C4
Internal error. Access to the connection end point is temporarily unavailable.
S7-1200 Programmable controller
882
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
TDIAG_Status Structure
The table below details the form of the TDIAG_Status structure. The value of each element
is only valid if the instruction has been executed without errors. If an error occurs, the
content of the parameters will not change:
Name
Data type
Description
The following parameters are in the TDIAG_Status structure:
InterfaceID
HW_ANY
Interface ID (LADDR) of the CPU or the CM/CP.
ID
CONN_OUC
ID of the connection diagnosed. Following a successful call, the value of this element is identical to the parameter ID of the "T_DIAG" instruction.
ConnectionType
BYTE
Protocol type used for connection:
ActiveEstablished
BOOL
•
0x01: Not used.
•
...
•
0x0B: TCP protocol (IP_v4)
•
0x0C: ISO-on-TCP protocol (RFC1006)
•
0x0D: TCP protocol (DNS)
•
0x0E: Dial-in protocol
•
0x0F: WDC protocol
•
0x10: SMTP protocol
•
0x11: TCP protocol
•
0x12: TCP and ISO-on-TCP protocol (RFC1006)
•
0x13: UDP protocol
•
0x14: Reserved
•
0x15: PROFIBUS bus access protocol (FDL)
•
0x16: ISO 8073 transport protocol (ISO native)
•
...
•
0x20: SMTP or SMTPS protocol - based on IPv4
•
0x21: SMTP or SMTPS protocol - based on IPv6
•
0x22: SMTP or SMTPS protocol - based on FQDN (Fully Qualified Domain
Name)
•
...
•
0x70: S7 connection
•
Other: Reserved
•
FALSE: Locally, the passive connection end point
•
TRUE: Locally, the active connection end point
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
883
Communication
11.2 PROFINET
Name
Data type
Description
State
BYTE
Current status of the connection end point
Kind
BYTE
•
0x00: Not used.
•
0x01: Connection terminated. Temporary status, for example, after the
"T_RESET" instruction is called. The system then automatically attempts to reestablish the connection.
•
0x02: The active connection end point is attempting to establish a connection to
the remote communication partner.
•
0x03: The passive connection end point is waiting for establishment of the connection to the remote communication partner.
•
0x04: Connection established.
•
0x05: The connection is being terminated. This may be because the "T_RESET"
or "T_DISCON" instruction has been called. Other possible reasons are protocol
errors and line breaks.
•
0x06..0xFF: Not used.
Mode of the connection end point:
•
0x00: Not used.
•
0x01: Configured, static connection which has been configured and loaded to
the CPU.
•
0x02: Configured, dynamic connection which has been configured and loaded to
the CPU (not currently supported).
•
0x03: Programmed connection generated in the user program with the instruction "TCON". A call of the instruction "TDISCON" or a transition to CPU STOP
status has destroyed the connection end point.
•
0x04: Temporary, dynamic connection established by the engineering station
(ES) or operator station (OS), for example. (this connection type cannot currently be diagnosed as there is no ID).
•
0x05..0xFF: Not used.
SentBytes
UDINT
Number of data bytes sent.
ReceivedBytes
UDINT
Number of data bytes received.
S7-1200 Programmable controller
884
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8.13
TMAIL_C (Send an email using the Ethernet interface of the CPU) instruction
Overview
You use the "TMAIL_C" instruction to send an e-mail using the Ethernet interface of the S71200 CPU.
The TMAIL_C instruction has two functionalities:
● Email over the CPU Interface (only SMTP without SSL)
● Email over a CP Interface (either SMTP without SSL or SMTP with SSL) If you want to
use the SSL functionality, you must set the TMAIL_C input parameter CERTINDEX = 1
and use the CP Interface. Also, the correct certificate must be stored in CP cert storage.
The instruction can only be used once the hardware has been configured and if the network
infrastructure allows for a communication connection to the mail server.
Table 11- 36 TMAIL_C instruction
LAD / FBD
1
SCL
"TMAIL_C_DB"(
req:=_bool_in_,
to_s:=_string_in_,
cc:=_string_in_,
subject:=_string_in_,
text:=_string_in_,
attachment:=_variant_in_,
attachment_name:=_string_in_,
mail_addr_param:=_string_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_);
Description
The TMAIL_C instruction sends
an e-mail using the Ethernet
interface of the S7-1200 CPU.
STEP 7 automatically creates the DB when you insert the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
885
Communication
11.2 PROFINET
You define the content of the e-mail, and the connection data, using the following
parameters:
● You define the recipient addresses with the parameters TO_S and CC.
● You define the content of the e-mail with the parameters SUBJECT and TEXT.
● You can define an attachment using VARIANT pointers at the ATTACHMENT and
ATTACHMENT_NAME parameters.
● The connection data are defined, and addressing and authentication for the mail server
executed, using the system data type Tmail_v4 or Tmail_FQDN at the
MAIL_ADDR_PARAM parameter. If you are using the interface of the S7-1200 CPU, the
system data type Tmail_v4 must be used. In this case, the e-mail can only be sent using
SMTP.
● You start the sending of an e-mail with an edge change from "0" to "1" for the REQ
parameter.
● The job status is indicated by the output parameters "BUSY", "DONE", "ERROR" and
"STATUS".
You cannot send an SMS directly with the "TMAIL_C" instruction. Whether or not the e-mail
can be forwarded by the mail server as an SMS depends on your telecommunications
provider.
Operation of the instruction
The "TMAIL_C" instruction works asynchronously, which means its execution extends over
multiple calls. You must specify an instance when you call the instruction "TMAIL_C".
In the following cases, the connection to the mail server will be lost:
● If the CPU switches to STOP while "TMAIL_C" is active.
● If communication problems occur at the Industrial Ethernet bus. In this case, the transfer
of the e-mail will be interrupted and it will not reach its recipient.
The connection is also canceled once the instruction has been successfully executed and
the e-mail sent.
NOTICE
Changing user programs
You can change the parts of your user program that directly affect calls of "TMAIL_C" only
when:
• The CPU is in "STOP" mode.
• No e-mail is being sent (REQ = 0 and BUSY = 0).
This relates, in particular, to deleting and replacing program blocks that contain "TMAIL_C"
calls or calls for the instance of "TMAIL_C".
Ignoring this restriction can tie up connection resources. The automation system can
change to an undefined status with the TCP/IP communication functions via Industrial
Ethernet.
A warm or cold restart of the CPU is required after the changes are transferred.
S7-1200 Programmable controller
886
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Data consistency
The TO_S, CC, SUBJECT, TEXT, ATTACHMENT and MAIL_ADDR_PARAM parameters
are applied by the "TMAIL_C" instruction while it is running, which means that they may only
be changed after the job has been completed (BUSY = 0).
SMTP authentication
Authentication refers here to a procedure for verifying identity, for example, with a password
query.
If you are using the S7-1200 CPU interface, the instruction "TMAIL_C" supports the SMTP
authentication procedure AUTH-LOGIN which is required by most mail servers. For
information about the authentication procedure of your mail server, please refer to your mail
server manual or the website of your Internet service provider.
● Before you can use the AUTH-LOGIN authentication procedure, the "TMAIL_C"
instruction requires the user name with which it is to log on to the mail server. This user
name corresponds to the user name with which you set up a mail account on your mail
server. It is transferred via the UserName parameter to the structure at parameter
MAIL_ADDR_PARAM.
If no user name is specified at the MAIL_ADDR_PARAM parameter, the AUTH-LOGIN
authentication procedure is not used. The e-mail is then sent without authentication.
● To log on, the "TMAIL_C" instruction also requires the associated password. This
password corresponds to the password you specified when you set up your mail account.
It is transferred via the PassWord parameter to the structure at parameter
MAIL_ADDR_PARAM.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
887
Communication
11.2 PROFINET
Data types for the parameters
The following table shows the parameters of the "TMAIL_C" instruction:
Parameter
Declaration
Data type
Memory
area
REQ
Input
BOOL
I, Q, M, D,
L, T, C or
constant
TO_S
(Page 891)
Input
STRING
D
Description
Control parameter REQUEST: Activates the sending of an e-mail upon a
rising edge.
Recipient addresses
STRING with a maximum length of 180
characters (bytes).
For the e-mail address format, please
see the example in the parameter
description.
CC
(Page 891)
Input
STRING
D
CC recipient addresses (optional)
STRING with a maximum length of 180
characters (bytes).
Same e-mail address format as for the
TO_S parameter. If an empty string is
assigned here, the e-mail is not sent to
a CC recipient.
SUBJECT
Input
STRING
D
Subject of the e-mail
STRING with a maximum length of 180
characters (bytes).
TEXT
Input
STRING
D
Text of the e-mail (optional)
STRING with a maximum length of 180
characters (bytes). If an empty string is
assigned at this parameter, the e-mail
is sent without text.
ATTACHMEN
T
Input
ATTACHMEN
T_NAME
Input
MAIL_ADDR_
PARAM
(Page 890)
Input
VARIANT
D
E-mail attachment (optional)
Reference to a byte/word/double word
field (ArrayOfByte, ArrayOfWord or
ArrayOfDWord) with a maximum length
of 64 bytes. If no value is assigned, the
e-mail is sent without an attachment.
VARIANT
D
E-mail attachment name (optional)
Reference to a character string with a
maximum length of 50 characters
(bytes) to define the file name of the
attachment. If an empty string is assigned at this parameter, the e-mail
attachment will be sent with the file
name "attachment.bin".
VARIANT
D
Connection parameter and address of
the e-mail server
To define the connection parameters,
use the structure Tmail_v4 or
Tmail_FQDN (see parameter description).
S7-1200 Programmable controller
888
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Parameter
Declaration
Data type
DONE
(Page 892)
Output
BOOL
BUSY
(Page 892)
ERROR
(Page 892)
STATUS
(Page 892)
Output
Output
Output
BOOL
BOOL
WORD
Memory
area
I, Q, M, D, L
I, Q, M, D, L
I, Q, M, D, L
I, Q, M, D, L
Description
Status parameter
•
DONE = 0: Job not yet started or
still executing.
•
DONE = 1: Job was executed without errors.
Status parameter
•
BUSY=0: The processing of
"TMAIL_C" was stopped.
•
BUSY = 1: E-mail transmission is
not yet complete.
Status parameter
•
ERROR = 0: No error has occurred.
•
ERROR = 1: An error occurred
during processing. STATUS supplies detailed information on the
type of error.
Status parameter
Return value or error information of the
"TMAIL_C" instruction (see parameter
description).
You will find more detailed information on valid data types in "Overview of valid data types".
Note
Optional parameters
The optional parameters CC, TEXT, and ATTACHMENT are only sent with the e-mail if the
corresponding parameters contain a string of length > 0.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
889
Communication
11.2 PROFINET
MAIL_ADDR_PARAM parameter
At the MAIL_ADDR_PARAM parameter, you define the connection for sending the e-mail in
the structure Tmail_v4 or Tmail_FQDN, and save the e-mail server address and login details.
The structure you use at the MAIL_ADDR_PARAM parameter depends on the format in
which the e-mail server is to be addressed:
● Tmail_v4: Addressing by IP address (IPv4).
● Tmail_FQDN: Addressing by fully qualified domain name (FQDN).
Which structure you can use depends on the interface addressed at the InterfaceId
parameter. If you want to use the "TMAIL_C" instruction with the internal interface, the
structure Tmail_v4 must be used at the MAIL_ADDR_PARAM parameter.
Table 11- 37 Tmail_v4: Addressing the mail server by IP address (IPv4)
Parameter
Data type
Tmail_v4
Struct
InterfaceId
Description
LADDR
Hardware identifier of the interface
ID
CONN_OUC
Connection ID
ConnectionType
BYTE
Connection type. Select 16#20 as the connection type for
IPv4.
ActiveEstablished
BOOL
Status bit. Set to "1" once the connection is established.
CertIndex
BYTE
=0: SMTP used (Simple Mail Transfer Protocol). SMTP
must be used if the e-mail is being sent via the interface of
an S7-1200 CPU.
WatchDogTime
TIME
Execution watchdog. Use this parameter to define the
maximum execution time for the send operation.
Note: Connection establishment can take longer (approx.
one minute) if the connection is slow. When you specify the
WATCH_DOG_TIME parameter, remember to allow for the
time required to establish the connection.
The connection is terminated once the specified time has
elapsed.
MailServerAddress
IP_v4
IP address of the mail server. IPv4 in the following format:
XXX.XXX.XXX.XXX (decimal).
Example: 192.142.131.237.
UserName
STRING[254]
Mail server login name
PassWord
STRING[254]
Mail server password
From
EMAIL_ADDR
E-mail sender address, which is defined using the following
two STRING parameters. For example: "myname@mymailserver.com".
LocalPartPlusAtSign
STRING[64]
Local part of sender address, including @ sign. Example:
"myname@".
FullQualifiedDomainName
STRING[254]
Fully Qualified Domain Name ( FQDN for short) of the mail
server. Example: "mymailserver.com".
S7-1200 Programmable controller
890
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 38 Tmail_FQDN: Addressing the mail server by FQDN
Parameter
Tmail_v6
Data type
Description
Struct
Tmail_FQDN
LADDR
Hardware identifier of the interface
ID
CONN_OUC
Connection ID
ConnectionType
BYTE
Connection type. Select 16#22 as the connection type for
FQDN.
ActiveEstablished
BOOL
Status bit. Set to "1" once the connection is established.
CertIndex
BYTE
=0: SMTP used (Simple Mail Transfer Protocol). SMTP
must be used if the e-mail is being sent via the interface of
an S7-1200 CPU.
WatchDogTime
TIME
Execution watchdog. Use this parameter to define the maximum execution time for the send operation.
Note: Connection establishment can take longer (approx.
one minute) if the connection is slow. When you specify the
WATCH_DOG_TIME parameter, remember to allow for the
time required to establish the connection.
The connection is terminated once the specified time has
elapsed.
MailServerAddress
STRING[254]
FQDN (Fully Qualified Domain Name) of the mail server.
The mail server is addressed using the fully qualified domain name.
UserName
STRING[254]
Mail server login name
PassWord
STRING[254]
Mail server password
From
Struct
E-mail sender address, which is defined using the following
two STRING parameters. For example: "myname@mymailserver.com".
LocalPartPlusAtSign
STRING[64]
Local part of sender address, including @ sign. Example:
"myname@".
FullQualifiedDomainName
STRING[254]
Fully Qualified Domain Name (FQDN for short) of the mail
server. Example: "mymailserver.com".
Example: "www.mymailserver.com.".
TO_S and CC parameters
The TO_S and CC parameters are strings, for example, with the following content:
● ,
● ,
Note the following rules when entering the parameters:
● A space and an opening pointed bracket "<" must be entered before each address.
● A closing pointed bracket ">" must be entered after each address.
● A comma must be entered between the addresses in TO and CC.
For runtime and memory space reasons, the "TMAIL_C" instruction does not perform a
syntax check of parameter TO_S or CC
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
891
Communication
11.2 PROFINET
DONE, BUSY and ERROR parameters
The output parameters DONE, BUSY and ERROR are each displayed for only one cycle if
the status of the BUSY output parameter changes from "1" to "0".
The following table shows the relationship between DONE, BUSY, and ERROR. Using this
table, you can determine the current status of the instruction "TMAIL_C and when the
sending of the e-mail is complete.
DONE
BUSY
ERROR
Description
0
1
0
The job is being processed.
1
0
0
Job successfully completed.
0
0
1
The job ended with an error. The cause of the error can be
found in the STATUS (Page 892) parameter.
0
0
0
The "TMAIL_C" instruction was not assigned a (new) job.
STATUS parameter
The following table shows the return values of TMAIL_C at the STATUS parameter:
Return value
Explanation
Notes
The processing of TMAIL_C was
completed without errors.
Error-free completion of TMAIL_C does not
mean that the e-mail sent will necessarily
arrive.
STATUS*
(W#16#...):
0000
Incorrectly entering the recipient addresses
does not generate a status error of the
TMAIL_C instruction. In this case, there is no
guarantee that the e-mail will be sent to other
recipients, even if these were entered correctly.
7001
TMAIL_C is active (BUSY = 1).
First call: Job triggered.
7002
TMAIL_C is active (BUSY = 1).
Intermediate call: Job already active.
8xxx
The processing of TMAIL_C was
completed with an error code of the
communication instructions called
internally.
For detailed information, refer to the STATUS
parameter descriptions for the TCON,
TDISCON, TSEND and TRCV (Page 857)
communication instructions.
8010
Error during connection establishment You will find further information on evaluation
in the SFB_STATUS parameter of the instance
data block. The error code displayed at the
SFB_STATUS parameter is explained in the
STATUS parameter description for the TCON
(Page 857) instruction.
8011
Error sending the data
You will find further information on evaluation
in the SFB_STATUS parameter of the instance
data block. The error code displayed at the
SFB_STATUS parameter is explained in the
STATUS parameter description for the TSEND
(Page 857) instruction.
S7-1200 Programmable controller
892
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Return value
Explanation
Notes
8012
Error receiving the data
You will find further information on evaluation
in the SFB_STATUS parameter of the instance
data block. The error code displayed at the
SFB_STATUS parameter is explained in the
STATUS parameter description for the TRCV
(Page 857) instruction.
8013
Error during connection establishment You will find further information on evaluation
in the SFB_STATUS parameter of the instance
data block. The error code displayed at the
SFB_STATUS parameter is explained in the
STATUS parameter description for the TCON
(Page 857) and TDISCON (Page 857) instructions.
8014
Establishment of a connection is not
possible.
You may have entered an incorrect mail server
IP address (MailServerAddress (Page 890)) or
too short a time span (WatchDogTime
(Page 890)) for connection establishment. It is
also possible that the CPU has no connection
to the network or that the CPU configuration is
incorrect.
8015
Incorrect data type for
MAIL_ADDR_PARAM
The only valid data types are the system data
types (structures) Tmail_v4 and TMail_FQDN.
8016
Incorrect data type for the
ATTACHMENT parameter
The only valid data types are ArrayOfByte,
ArrayOfWord and ArrayOfDWord.
8017
Incorrect data length for the
ATTACHMENT parameter
Data length must be <= 65534 bytes.
82xx, 84xx,
or 85xx
The error message originates from
the mail server and corresponds,
except for the "8", to the error number
of the SMTP protocol.
You will find more detailed information on the
SMTP error code and other error codes in the
SMTP protocol on the Internet or in the error
documentation of the mail server. You can
also view the most recent error message from
the mail server in your instance DB in the
BUFFER1 parameter. You will find the last
data sent by the TMAIL_C instruction under
DATEN in the instance DB.
STATUS*
(W#16#...):
The following lines list several error
codes that can occur.
8450
Action not executed: Mailbox not
available/cannot be reached
Try again later.
8451
Action aborted: Local processing error Try again later.
8500
Syntax error: Error not recognized.
This also includes the error when a
command string is too long. This can
also occur when the e-mail server
does not support the LOGIN authentication procedure.
Check the parameters of TMAIL_C. Try to
send an e-mail without authentication. To do
this, replace the content of the UserName
parameter with an empty string. If no user
name is specified, the LOGIN authentication
procedure is not used.
8501
Syntax error: Incorrect input at a parameter
Possible cause: Incorrect address at the TO_S
or CC parameter (see also: TO_S and CC
parameters (Page 891)).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
893
Communication
11.2 PROFINET
Return value
Explanation
Notes
8502
Command unknown or not implemented
Check your entries, in particular the FROM
parameter. It may be incomplete and you may
have forgotten the "@" or "." (see also: TO_S
and CC parameters (Page 891)).
8535
SMTP authentication incomplete
You have possibly entered an incorrect user
name or incorrect password.
8550
Mail server cannot be reached. You
have no access rights.
You may have entered an incorrect user name
or password, or the mail server may not support your login. Another cause of error could
be a mistake in the domain name after the "@"
at the TO_S or CC parameter (see also: TO_S
and CC parameters (Page 891)).
8552
Action aborted: Assigned memory
size has been exceeded
Try again later.
8554
Transfer failed
Try again later.
STATUS*
(W#16#...):
* You can display error codes as integer or hexadecimal values in the program editor.
11.2.8.14
UDP
UDP is a standard protocol described by RFC 768: User Datagram Protocol. UDP provides a
mechanism for one application to send a datagram to another; however, delivery of data is
not guaranteed. This protocol has the following features:
● A quick communications protocol
● Suitable for small-sized to medium data amounts (up to 1472 bytes)
● UDP is a simpler transport control protocol than TCP, with a thin layer that yields low
overheads
● Can be used very flexibly with many third-party systems
● Routing-capable
● Uses port numbers to direct the datagrams
● Messages are unacknowledged: The application is required to take responsibility for error
recovery and security
● Programming effort is required for data management due to the SEND / RECEIVE
programming interface
UDP supports broadcast communication. To use broadcast, you must configure the IP
address portion of the ADDR configuration. For example: A CPU with an IP address of
192.168.2.10 and subnet mask of 255.255.255.0 would use a broadcast address of
192.168.2.255.
S7-1200 Programmable controller
894
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8.15
TUSEND and TURCV
The following instructions control the UDP communication process:
● TCON establishes the communication between the client and server (CPU) PC.
● TUSEND and TURCV send and receive data.
● TDISCON disconnects the communication between the client and server.
Refer to TCON, TDISCON, TSEND, and TRCV (Page 857) in the "TCP and ISO-on-TCP"
section for more information on the TCON and TDISCON communication instructions.
Table 11- 39 TUSEND and TURCV instructions
LAD / FBD
1
SCL
"TUSEND_DB"(
req:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
done=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
data:=_variant_inout_);
"TURCV_DB"(
en_r:=_bool_in_,
ID:=_word_in_,
len:=_udint_in_,
ndr=>_bool_out_,
busy=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
rcvd_len=>_udint_out_,
data:=_variant_inout_);
Description
The TUSEND instruction sends data via UDP to
the remote partner specified by the parameter
ADDR.
To start the job for sending data, call the TUSEND
instruction with REQ = 1.
The TURCV instruction receives data via UDP.
The parameter ADDR shows the address of the
sender. After successful completion of TURCV, the
parameter ADDR contains the address of the remote partner (the sender).
TURCV does not support ad hoc mode.
To start the job for receiving data, call the TURCV
instruction with EN_R = 1.
STEP 7 automatically creates the DB when you insert the instruction.
TCON, TDISCON, TUSEND, and TURCV operate asynchronously, which means that the job
processing extends over multiple instruction executions.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
895
Communication
11.2 PROFINET
Table 11- 40 TUSEND and TURCV data types for the parameters
Parameter and type
Data type
Description
REQ
IN
Bool
Starts the send job on a rising edge. The data is transferred from
the area specified by DATA and LEN.
IN
Bool
•
0: CPU cannot receive.
•
1: Enables the CPU to receive. The TURCV instruction is
ready to receive, and the receive job is processed.
(TUSEND)
EN_R
(TURCV)
ID
IN
Word
LEN
IN
UDInt
Reference to the associated connection between the user program and the communication level of the operating system. ID
must be identical to the associated parameter ID in the local
connection description.
Range of values: W#16#0001 to W#16#0FFF.
DONE
IN
Bool
(TUSEND)
NDR
OUT
Bool
(TURCV)
BUSY
ERROR
OUT
OUT
Bool
Bool
Number of bytes to be sent (TUSEND) or received (TURCV).
•
Default = 0. The DATA parameter determines the length of
the data to be sent or received.
•
Otherwise, range of values: 1 to 1472
Status parameter DONE (TUSEND):
•
0: Job is not yet started or still running.
•
1: Job completed without error.
Status parameter NDR (TURCV):
•
0: Job not yet started or still running.
•
1: Job has successfully completed.
•
1: Job is not yet completed. A new job cannot be triggered.
•
0: Job has completed.
Status parameters with the following values:
•
0: No error
•
1: Error occurred during processing. STATUS provides detailed information on the type of error.
STATUS
OUT
Word
Status information including error information. (Refer to the Error
and Status condition codes in the table below.)
RCVD_LEN
OUT
UDInt
Number of bytes received (TURCV)
S7-1200 Programmable controller
896
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Parameter and type
Data type
Description
DATA
Variant
Address of the sender area (TUSEND) or receive area
(TURCV):
ADDR
IN_OUT
IN_OUT
Variant
•
The process image input table
•
The process image output table
•
A memory bit
•
A data block
Pointer to the address of the receiver (for TUSEND) or sender
(for TURCV) (for example, P#DB100.DBX0.0 byte 8). The pointer may point to any memory area.
A structure of 8 bytes is required as follows:
•
First 4 bytes contain the remote IP address.
•
Next 2 bytes specify the remote port number.
•
Last 2 bytes are reserved.
The job status is indicated at the output parameters BUSY and STATUS. STATUS
corresponds to the RET_VAL output parameter of asynchronously functioning instructions.
The following table shows the relationships between BUSY, DONE (TUSEND), NDR
(TURCV), and ERROR. Using this table, you can determine the current status of the
instruction (TUSEND or TURCV) or when the sending (transmission) / receiving process is
complete.
Table 11- 41 Status of BUSY, DONE (TUSEND) / NDR (TURCV), and ERROR parameters
1
BUSY
DONE / NDR
ERROR
Description
TRUE
irrelevant
irrelevant
The job is being processed.
FALSE
TRUE
FALSE
The job was completed successfully.
FALSE
FALSE
TRUE
The job was ended with an error. The cause of the error can be
found in the STATUS parameter.
FALSE
FALSE
FALSE
The instruction was not assigned a (new) job.
Due to the asynchronous function of the instructions: For TUSEND, you must keep the data in the sender area consistent until the DONE parameter or the ERROR parameter assumes the value TRUE. For TURCV, the data in the receiver area are only consistent when the NDR parameter assumes the value TRUE.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
897
Communication
11.2 PROFINET
Table 11- 42 TUSEND and TURCV condition codes for ERROR and STATUS
ERROR
STATUS
Description
0
0000
•
Send job completed without error (TUSEND).
•
New data were accepted. The current length of the received data is shown in
RCVD_LEN (TURCV).
•
No job processing active (TUSEND)
•
Block not ready to receive (TURCV)
•
Start of job processing, data being sent (TUSEND): During this processing, the
operating system accesses the data in the DATA send area.
•
Block is ready to receive, receive job was activated (TURCV).
•
Follow-on instruction execution (REQ irrelevant), job being processed (TUSEND):
During this processing, the operating system accesses the data in the DATA send
area.
•
Follow-on instruction execution, job being processed: During this processing, the
TURCV instruction writes data to the receive area. For this reason, an error could
result in inconsistent data in the receive area.
0
0
0
7000
7001
7002
1
8085
LEN parameter is greater than the largest permitted value, has the value 0 (TUSEND),
or you changed the value of the LEN or DATA parameter since the first instruction execution (TURCV).
1
8086
The ID parameter is not in the permitted address range.
1
8088
•
LEN parameter is larger than the memory area (TUSEND) or receive area (TURCV)
specified in DATA.
•
Receive area is too small (TURCV).
1
8089
ADDR parameter does not point to a data block.
1
80A1
Communications error:
•
The specified connection between user program and communications layer of the
operating system has not yet been established.
•
The specified connection between the user program and the communication layer of
the operating system is currently being terminated. Transmission (TUSEND) or a receive job (TURCV) over this connection is not possible.
•
The interface is being reinitialized.
1
80A4
IP address of the remote connection end point is invalid; it is possible that it matches
the local IP address (TUSEND).
1
80B3
•
The set protocol variant (connection_type parameter in the connection description)
is not UDP. Please use the TSEND or TRCV instruction.
•
ADDR parameter: Invalid settings for port number (TUSEND)
•
A block with this ID is already being processed in a different priority class.
•
Internal lack of resources
1
1
80C3
80C4
Temporary communications error:
•
The connection between the user program and the communication level of the operating system cannot be established at this time (TUSEND).
•
The interface is receiving new parameters (TUSEND).
•
The connection is currently being reinitiated (TURCV).
S7-1200 Programmable controller
898
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Connection Ethernet protocols
Every CPU has an integrated PROFINET port, which supports standard PROFINET
communications. The TUSEND and TURCV instructions support the UDP Ethernet protocol.
Refer to "Configuring the Local/Partner connection path" (Page 807)" in the "Device
configuration" chapter for more information.
Operations
Both partners are passive in UDP communication. Typical parameter start values for the
"TCON_Param" data type are shown in the following figures. Port numbers
(LOCAL_TSAP_ID) are written in a 2-byte format. All ports except for 161, 34962, 34963,
and 34964 are allowed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
899
Communication
11.2 PROFINET
The TUSEND instruction sends data through UDP to the remote partner specified in the
"TADDR_Param" data type. The TURCV instruction receives data through UDP. After a
successful execution of the TURCV instruction, the "TADDR_Param" data type shows the
address of the remote partner (the sender), as shown in the figures below.
S7-1200 Programmable controller
900
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.8.16
T_CONFIG
The T_CONFIG instruction can change the Ethernet address, the PROFINET device name,
or the IP addresses of the NTP servers for time-of-day synchronization from within the user
program. The following features can be adjusted permanently or temporarily:
● IP address
● Subnet mask
● Router address
● Station name
● IP addresses of up to four NTP servers
Note
Located in the CPU "Properties", "Ethernet address" page, the "IP address is set directly
at the device" (Page 908) radio button allows you to change the IP address online or by
using the "T_CONFIG" instruction after the program is downloaded.
Located in the CPU "Properties", "Ethernet address" page, the "PROFINET device name
is set directly at the device" (Page 910) radio button allows you to change the PROFINET
device name online or by using the "T_CONFIG" instruction after the program is
downloaded.
Located in the CPU "Properties", "Time synchronization" page, the "Enable time
synchronization via NTP server" (Page 911) box allows you to change the IP addresses
of up to four NTP servers.
Note
You cannot execute more than one T_CONFIG instruction at a time.
Note
Changes to the IP address or name of station of the CPU can be temporary or
permanent. Changes to the NTP server IP addresses can only be temporary:
• A permanent change indicates that the change is retentive, meaning that the change
persists through a power failure.
• A temporary change indicates that the change is volatile and reverts to the original
value after a power loss.
Table 11- 43 T_CONFIG instruction
LAD / FBD
SCL
"T_CONFIG_DB"(
Req:=_bool_in_,
Interface:=_uint_in_,
Conf_Data:=_variant_in_,
Done=>_bool_out_,
Busy=>_bool_out_,
Error=>_bool_out_,
Status=>_dword_out_,
Err_Loc=>_dword_out_);
Description
Use the T_CONFIG instruction to change the IP
configuration parameters from your user program.
T_CONFIG works asynchronously. The execution
extends over multiple calls.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
901
Communication
11.2 PROFINET
Table 11- 44 T_CONFIG data types for the parameters
Parameter and type
Data type
Description
REQ
Input
Bool
Starts the instruction on the rising edge.
INTERFACE
Input
HW_Interface
ID of network interface
CONF_DATA
Input
Variant
Reference to the structure of the configuration data;
CONF_DATA is defined by a struct containing up to four
System Data Types (SDT).
DONE
Output
Bool
•
0: Job has not yet started or is still running.
•
1: Job was executed without error.
•
0: The job is complete.
•
1: The job is not yet complete. A new job cannot be
triggered.
BUSY
ERROR
Output
Output
Bool
Bool
Status parameters with the following values:
•
0: No error
•
1: Error occurred during processing. STATUS provides
detailed information on the type of error.
STATUS
Output
DWord
Status information including error information. (Refer to
the Error and Status condition codes in the table below.)
ERR_LOC
Output
DWord
Fault location (field ID and subfield location within the
CONF_DATA structure)
The IP configuration information is placed in the CONF_DATA data block, along with a
Variant pointer on parameter CONF_DATA referenced above. The successful execution of
the T_CONFIG instruction ends with the handover of the IP configuration data to the network
interface.
The status and error messages of the instruction "T_CONFIG" are output at the parameters
STATUS and ERR_LOC:
● The cause of the error is output at the parameter STATUS.
● The location of the error that occurred is output at the parameter ERR_LOC. The
following options are available here:
– 16#0000_0000: No error or error when calling the instruction (for example, errors
when assigning parameters to the instruction or in communication with the PROFINET
interface).
– 16#0001_0000: Error with the configuration data in the parameters of the system data
type IF_CONF_HEADER.
– 16#0001_000x: Error in the configuration data in the parameters of system data type
IF_CONF_V4 or IF_CONF_NOS or IF_CONF_NTP (x specifies the position of the bad
sub-block in the T_CONFIG structure. If the T_CONFIG structure contains, for
example, a sub-block for the IP address and a sub-block for the station name, and the
error is located in the sub-block for the station name, ERR_LOC has the value
0001_0002.)
S7-1200 Programmable controller
902
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
The following table shows the possible values for the parameters STATUS and ERR_LOC:
STATUS*
ERR_LOC*
Explanation
0000_0000
0000_0000
Order processing completed without errors.
0070_0000
0000_0000
No job processing active.
0070_0100
0000_0000
Start of the order processing.
0070_0200
0000_0000
Intermediate call (REQ irrelevant).
C08x_yy00
0000_0000
General error information.
C080_8000
0000_0000
Error at call of the instruction:
C080_8100
0000_0000
C080_8700
0000_0000
C080_8800
0001_0000
The hardware ID at the parameter Interface is invalid.
Error at call of the instruction:
The hardware ID at the parameter Interface does not address a PROFINET interface.
Error at call of the instruction:
Incorrect length of the data block at the parameter CONF_DATA.
Error in the system data type IF_CONF_HEADER:
The parameter FieldType has an invalid value. Use the value "0" for FieldType.
C080_8900
0001_0000
Error in the system data type IF_CONF_HEADER:
The parameter FieldId has an invalid value or was used several times. Use the value "0" for
FieldId.
C080_8A00
0001_0000
Error in the system data type IF_CONF_HEADER:
Incorrect number at the parameter SubfieldCount. Enter the correct number of system data
types IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP being used.
C080_8B00
0001_000x
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
The parameter Id has an invalid value. For IF_CONF_V4 use "30", for IF_CONF_NOS "40",
for IF_CONF_NTP "17".
C080_8C00
0001_000x
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
C080_8D00
0001_000x
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
C080_8E00
0001_000x
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
Incorrect data type system used, wrong order or multiple use of a system data type.
The parameter Length has an incorrect or invalid value.
The parameter Mode has an incorrect or invalid value.
C080_9000
0001_000x
•
With IF_CONF_V4 and IF_CONF_NOS only the values "1" (permanent) or "2" (temporary) are permitted.
•
With IF_CONF_NTP only the value "2" (temporary) is permitted.
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
Configuration data cannot be applied. Possible cause:
C080_9400
0001_000x
•
With IF_CONF_V4: In the hardware configuration, the setting "Set IP address on the
device" was not selected..
•
With IF_CONF_NOS: In the hardware configuration, the setting "Set PROFINET device
name on the device" was not selected..
•
With IF_CONF_NTP: In the hardware configuration, the setting "Enable time synchronization via NTP server " was not selected and no IP address was set for NTP servers..
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
A parameter value is undefined or invalid.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
903
Communication
11.2 PROFINET
STATUS*
ERR_LOC*
Explanation
C080_9500
0001_000x
Error in the system data type IF_CONF_V4, IF_CONF_NOS, or IF_CONF_NTP:
C080_C200
0000_0000
The values of two parameters are inconsistent.
Error at call of the instruction:
The configuration data cannot be transferred. Possible cause: The PROFINET interface is
not accessible.
C080_C300
0000_0000
Error at call of the instruction:
Insufficient resources (for example, multiple calling of "T_CONFIG" with different parameters).
C080_C400
0000_0000
Error at call of the instruction:
Temporary communication error. Time indication for change to daylight saving time.
C080_D200
0000_0000
Error at call of the instruction:
Call not possible. Instruction is not supported by the selected PROFINET interface.
CONF_DATA Data block
The following diagram shows how the configuration data to be transferred is stored in the
configuration DB.
①
②
③
Configuration DB
Configuration data
Subfield 1
④
⑤
⑥
Subfield 2
Subfield n
Subfield-specific parameters
The configuration data of CONF_DB consists of a field that contains a header
(IF_CONF_Header) and several subfields. IF_CONF_Header provides the following
elements:
● field_type_id (data type UInt): Zero
● field_id (data type UInt): Zero
● subfield_cnt (data type UInt): Number of subfields
S7-1200 Programmable controller
904
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Each subfield consists of a header (subfield_type_id, subfield_length, subfield_mode) and
the subfield-specific parameters. Each subfield must consist of an even number of bytes.
The subfield_mode can support a value of 1 or 2. Please refer to the tables below.
Note
Only one field (IF_CONF_Header) is currently allowed. Its parameters field_type_id and
field_id must have the value zero. Other fields with different values for field_type_id and
field_id are subject to future extensions.
Table 11- 45 Subfields supported
subfield_type_id
Data type
Explanation
30
IF_CONF_V4
IP parameters: IP address, subnet mask, router address
40
IF_CONF_NOS
PROFINET IO device name (Name of station)
17
IF_CONF_NTP
Network Time Protocol (NTP)
Table 11- 46 Elements of the IF_CONF_V4 data type
Name
Data type
Start value
Description
Id
UInt
30
subfield_type_id
Length
UInt
18
subfield_length
Mode
UInt
0
subfield_mode (1: permanent or 2: temporary)
InterfaceAddress
IP_V4
-
Interface address
ADDR
Array [1..4] of Byte
ADDR[1]
Byte
0
IP address high byte: 200
ADDR[2]
Byte
0
IP address high byte: 12
ADDR[3]
Byte
0
IP address low byte: 1
ADDR[4]
Byte
0
IP address low byte: 144
SubnetMask
IP_V4
-
Subnet mask
ADDR
Array [1..4] of Byte
ADDR[1]
Byte
0
Subnet mask high byte: 255
ADDR[2]
Byte
0
Subnet mask high byte: 255
ADDR[3]
Byte
0
Subnet mask low byte: 255
ADDR[4]
Byte
0
Subnet mask low byte: 0
DefaultRouter
IP_V4
-
Default router
ADDR
Array [1..4] of Byte
ADDR[1]
Byte
0
Router high byte: 200
ADDR[2]
Byte
0
Router high byte: 12
ADDR[3]
Byte
0
Router low byte: 1
ADDR[4]
Byte
0
Router low byte: 1
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
905
Communication
11.2 PROFINET
Table 11- 47 Elements of the IF_CONF_NOS data type
Name
Data type
Start value
Description
Id
UInt
40
subfield_type_id
Length
UInt
246
subfield_length
Mode
UInt
0
subfield_mode (1: permanent or 2: temporary)
NOS (Name of
station)
Array[1..240] of Byte
0
Station name: You must occupy the ARRAY from the first
byte. If the ARRAY is longer than the station name to be assigned, you must enter a zero byte after the actual station
name (in conformity with IEC 61158-6-10). Otherwise, NOS is
rejected and the "T_CONFIG (Page 901)" instruction enters
the error code DW#16#C0809400 in STATUS. If you occupy
the first byte with zero, the station name is deleted.
The station name is subject to the following limitations:
● A name component within the station name, i.e., a character string between two dots,
must not exceed 63 characters.
● No special characters such as umlauts, brackets, underscore, slash, blank space, etc.
The only special character permitted is the dash.
● The station name must not begin or end with the "-" character.
● The station name must not begin with a number.
● The station name form n.n.n.n (n = 0, ... 999) is not permitted.
● The station name must not begin with the string "port-xyz" or "port-xyz-abcde" (a, b, c, d,
e, x, y, z = 0, ... 9).
Note
You can also create an ARRAY "NOS" that is shorter then 240 bytes, but not less than 2
bytes. In this case, you must adjust the "Length" (length of subfield) tag accordingly.
S7-1200 Programmable controller
906
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 48 Elements of the IF_CONF_NTP data type
Name
Data type
Start value
Description
Id
UInt
17
subfield_type_id
Length
UInt
22
subfield_length
Mode
UInt
0
subfield_mode (2: temporary)
NTP_IP
Array[1...4] of IP_V4
-
IP addresses of NTP servers
NTP_IP[1]
IP_V4
ADDR
IP addresses of NTP server 1
Array[1...4] of Byte
0
ADDR[1]
Byte
0
IP address high byte
ADDR[2]
Byte
0
IP address high byte
ADDR[3]
Byte
0
IP address low byte
ADDR[4]
Byte
0
IP address low byte
NTP_IP[2]
IP_V4
ADDR
IP addresses of NTP server 2
Array[1...4] of Byte
0
ADDR[1]
Byte
0
IP address high byte
ADDR[2]
Byte
0
IP address high byte
ADDR[3]
Byte
0
IP address low byte
ADDR[4]
Byte
0
IP address low byte
NTP_IP[3]
IP_V4
ADDR
IP addresses of NTP server 3
Array[1...4] of Byte
0
ADDR[1]
Byte
0
IP address high byte
ADDR[2]
Byte
0
IP address high byte
ADDR[3]
Byte
0
IP address low byte
ADDR[4]
Byte
0
IP address low byte
NTP_IP[4]
IP_V4
ADDR
IP addresses of NTP server 4
Array[1...4] of Byte
0
ADDR[1]
Byte
0
IP address high byte
ADDR[2]
Byte
0
IP address high byte
ADDR[3]
Byte
0
IP address low byte
ADDR[4]
Byte
0
IP address low byte
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
907
Communication
11.2 PROFINET
Example: Using the T_CONFIG instruction to change IP parameters
In the following example, in the "addr" subfield, the "InterfaceAddress" (IP address),
"SubnetMask", and "DefaultRouter" (IP router) are changed. In the CPU "Properties",
"Ethernet address" page, you must select the "IP address is set directly at the device" radio
button to enable you to change the IP parameters using the "T_CONFIG" instruction after the
program is downloaded.
S7-1200 Programmable controller
908
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
909
Communication
11.2 PROFINET
Example: Using the T_CONFIG instruction to change IP parameters and PROFINET IO device
names
In the following example, both the "addr" and "nos" (Name of station) subfields are changed.
In the CPU "Properties", "Ethernet address" page, you must select the "PROFINET device
name is set directly at the device" check box to enable you to change the PROFINET device
name using the "T_CONFIG" instruction after the program is downloaded.
S7-1200 Programmable controller
910
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Example: Using the T_CONFIG instruction to change IP addresses in the NTP servers
In the following example, in the "ntp" (Network Time Protocol (NTP) server) subfield, the
T_CONFIG instruction changes the IP addresses of up to four NTP servers.
In the CPU Properties, PROFINET interface [X1], Time synchronization page, you configure
NTP synchronization by selecting the "Enable time synchronization via NTP server" check
box as shown in the figure below. You can then change the IP addresses in the NTP servers
using the "T_CONFIG" instruction after the program is downloaded.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
911
Communication
11.2 PROFINET
11.2.8.17
Common parameters for instructions
REQ input parameter
Many of the Open User Communication instructions use the REQ input to initiate the
operation on a low to high transition. The REQ input must be high (TRUE) for one execution
of an instruction, but the REQ input can remain TRUE for as long as desired. The instruction
does not initiate another operation until it has been executed with the REQ input FALSE so
that the instruction can reset the history state of the REQ input. This is required so that the
instruction can detect the low to high transition to initiate the next operation.
When you place one of these instructions in your program, STEP 7 prompts you to identify
the instance DB. Use a unique DB for each instruction call. This ensures that each
instruction properly handles inputs such as REQ.
ID input parameter
This is a reference to the "Local ID (hex)" on the "Network view" of "Devices and networks"
in STEP 7 and is the ID of the network that you want to use for this communication block.
The ID must be identical to the associated parameter ID in the local connection description.
DONE, NDR, ERROR, and STATUS output parameters
These instructions provide outputs describing the completion status:
Table 11- 49 Open User Communication instruction output parameters
Parameter
Data type
Default
Description
DONE
Bool
FALSE
Is set TRUE for one execution to indicate that the last request
completed without errors; otherwise, FALSE.
NDR
Bool
FALSE
Is set TRUE for one execution to indicate that the requested action
has completed without error and new data has been received;
otherwise, FALSE.
BUSY
Bool
FALSE
Is set TRUE when active to indicate that:
•
The job is not yet complete.
• A new job cannot be triggered.
Is set FALSE when job is complete.
ERROR
Bool
FALSE
Is set TRUE for one execution to indicate that the last request
completed with errors, with the applicable error code in STATUS;
otherwise, FALSE.
STATUS
Word
0
Result status:
•
If the DONE or NDR bit is set, then STATUS is set to 0 or to an
informational code.
•
If the ERROR bit is set, then STATUS is set to an error code.
If none of the above bits are set, then the instruction returns
status results that describe the current state of the function.
STATUS retains its value for the duration of the execution of the
function.
•
S7-1200 Programmable controller
912
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Note
Note that DONE, NDR, and ERROR are set for one execution only.
Restricted TSAPs and port numbers for passive ISO and TCP communication
If you use the "TCON" instruction to set up and establish a passive communications
connection, the following port addresses are restricted and should not be used:
● ISO TSAP (passive):
– 01.00, 01.01, 02.00, 02.01, 03.00, 03.01
– 10.00, 10.01, 11.00, 11.01, ... BF.00, BF.01
● TCP port (passive): 5001, 102, 123, 20, 21, 25, 34962, 34963, 34964, 80
● UDP port (passive): 161, 34962, 34963, 34964
11.2.9
Communication with a programming device
A CPU can communicate with a STEP 7 programming device on a network.
Consider the following when setting up communications between a CPU and a programming
device:
● Configuration/Setup: Hardware configuration is required.
● No Ethernet switch is required for one-to-one communications; an Ethernet switch is
required for more than two devices in a network.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
913
Communication
11.2 PROFINET
11.2.9.1
Establishing the hardware communications connection
The PROFINET interfaces establish the physical connections between a programming
device and a CPU. Since Auto-Cross-Over functionality is built into the CPU, either a
standard or crossover Ethernet cable can be used for the interface. An Ethernet switch is not
required to connect a programming device directly to a CPU.
Follow the steps below to create the hardware connection between a programming device
and a CPU:
1. Install the CPU (Page 61).
2. Plug the Ethernet cable into the PROFINET port shown below.
3. Connect the Ethernet cable to the programming device.
①
PROFINET port
An optional strain relief is available to strengthen the PROFINET connection. For ordering
information, see Spare parts and other hardware (Page 1564).
11.2.9.2
Configuring the devices
If you have already created a project with a CPU, open your project in STEP 7.
If not, create a project and insert a CPU (Page 154) into the rack. In the project below, a
CPU is shown in the "Device View".
S7-1200 Programmable controller
914
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.9.3
Assigning Internet Protocol (IP) addresses
Assigning the IP addresses
In a PROFINET network, each device must also have an Internet Protocol (IP) address. This
address allows the device to deliver data on a more complex, routed network:
● If you have programming or other network devices that use an on-board adapter card
connected to your plant LAN or an Ethernet-to-USB adapter card connected to an
isolated network, you must assign IP addresses to them. Refer to "Assigning IP
addresses to programming and network devices" (Page 810) for more information.
● You can also assign an IP address to a CPU or network device online. This is particularly
useful in an initial device configuration. Refer to "Assigning an IP address to a CPU
online" (Page 810) for more information.
● After you have configured your CPU or network device in your project, you can configure
parameters for the PROFINET interface, to include its IP address. Refer to "Configuring
an IP address for a CPU in your project" (Page 813) for more information.
11.2.9.4
Testing your PROFINET network
After completing the configuration, you must download your project to the CPU. All IP
addresses are configured when you download the project.
The CPU "Download to device" function and its "Extended download to device" dialog can
show all accessible network devices and whether or not unique IP addresses have been
assigned to all devices. Refer to "Testing the PROFINET network" (Page 819) for more
information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
915
Communication
11.2 PROFINET
11.2.10
HMI-to-PLC communication
The CPU supports PROFINET communications connections to HMIs (Page 32). The
following requirements must be considered
when setting up communications between
CPUs and HMIs:
Configuration/Setup:
● The PROFINET port of the CPU must be configured to connect with the HMI.
● The HMI must be setup and configured.
● The HMI configuration information is part of the CPU project and can be configured and
downloaded from within the project.
● No Ethernet switch is required for one-to-one communications; an Ethernet switch is
required for more than two devices in a network.
Note
The rack-mounted CSM1277 4-port Ethernet switch can be used to connect your CPUs
and HMI devices. The PROFINET port on the CPU does not contain an Ethernet
switching device.
Supported functions:
● The HMI can read/write data to the CPU.
● Messages can be triggered, based upon information retrieved from the CPU.
● System diagnostics
S7-1200 Programmable controller
916
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 50 Required steps in configuring communications between an HMI and a CPU
Step
1
Task
Establishing the hardware communications connection
A PROFINET interface establishes the physical connection between an HMI and a CPU. Since AutoCross-Over functionality is built into the CPU, you can use either a standard or crossover Ethernet cable
for the interface. An Ethernet switch is not required to connect an HMI and a CPU.
Refer to "Communication with a programming device: Establishing the hardware communications connection" (Page 914) for more information.
2
Configuring the devices
Refer to "Communication with a programming device: Configuring the devices" (Page 914) for more information.
3
Configuring the logical network connections between an HMI and a CPU
Refer to "HMI-to-PLC communication: Configuring the logical network connections between two devices"
(Page 917) for more information.
4
Configuring an IP address in your project
Use the same configuration process; however, you must configure IP addresses for the HMI and the CPU.
Refer to "Device configuration: Configuring an IP address for a CPU in your project" (Page 814) for more
information.
5
Testing the PROFINET network
You must download the configuration for each CPU and HMI device.
Refer to "Device configuration: Testing the PROFINET network" (Page 819) for more information.
11.2.10.1
Configuring logical network connections between two devices
After you configure the rack with the CPU, you are now ready to configure your network
connections.
In the Devices and Networks portal, use the "Network view" to create the network
connections between the devices in your project. First, click the "Connections" tab, and then
select the connection type with the dropdown, just to the right (for example, an ISO on TCP
connection).
To create a PROFINET connection, click the green (PROFINET) box on the first device, and
drag a line to the PROFINET box on the second device. Release the mouse button and your
PROFINET connection is joined.
Refer to "Device Configuration: Creating a network connection" (Page 806) for more
information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
917
Communication
11.2 PROFINET
11.2.11
PLC-to-PLC communication
A CPU can communicate with another CPU on a
network by using the TSEND_C and TRCV_C instructions.
Consider the following when setting up communications between two CPUs:
● Configuration/Setup: Hardware configuration is required.
● Supported functions: Reading/Writing data to a peer CPU
● No Ethernet switch is required for one-to-one communications; an Ethernet switch is
required for more than two devices in a network.
Table 11- 51 Required steps in configuring communications between two CPUs
Step
1
Task
Establishing the hardware communications connection
A PROFINET interface establishes the physical connection between two CPUs. Since Auto-Cross-Over
functionality is built into the CPU, you can use either a standard or crossover Ethernet cable for the interface. An Ethernet switch is not required to connect the two CPUs.
Refer to "Communication with a programming device: Establishing the hardware communications connection" (Page 914) for more information.
2
Configuring the devices
You must configure two CPUs in your project.
Refer to "Communication with a programming device: Configuring the devices" (Page 914) for more information.
3
Configuring the logical network connections between two CPUs
Refer to "PLC-to-PLC communication: Configuring logical network connections between two devices"
(Page 919) for more information.
4
Configuring an IP address in your project
Use the same configuration process; however, you must configure IP addresses for two CPUs (for example, PLC_1 and PLC_2).
Refer to "Device configuration: Configuring an IP address for a CPU in your project" (Page 814) for more
information.
5
Configuring transmit (send) and receive parameters
You must configure TSEND_C and TRCV_C instructions in both CPUs to enable communications between
them.
Refer to "Configuring communications between two CPUs: Configuring transmit (send) and receive parameters" (Page 919) for more information.
6
Testing the PROFINET network
You must download the configuration for each CPU.
Refer to "Device configuration: Testing the PROFINET network" (Page 819) for more information.
S7-1200 Programmable controller
918
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.11.1
Configuring logical network connections between two devices
After you configure the rack with the CPU, you are now ready to configure your network
connections.
In the Devices and Networks portal, use the "Network view" to create the network
connections between the devices in your project. First, click the "Connections" tab, and then
select the connection type with the dropdown, just to the right (for example, an ISO on TCP
connection).
To create a PROFINET connection, click the green (PROFINET) box on the first device, and
drag a line to the PROFINET box on the second device. Release the mouse button and your
PROFINET connection is joined.
Refer to "Device Configuration: Creating a network connection" (Page 806) for more
information.
11.2.11.2
Configuring the Local/Partner connection path between two devices
Configuring General parameters
You specify the communication parameters in the "Properties" configuration dialog of the
communication instruction. This dialog appears near the bottom of the page whenever you
have selected any part of the instruction.
Refer to "Device configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
In the "Address Details" section of the Connection parameters dialog, you define the TSAPs
or ports to be used. The TSAP or port of a connection in the CPU is entered in the "Local
TSAP" field. The TSAP or port assigned for the connection in your partner CPU is entered
under the "Partner TSAP" field.
11.2.11.3
Configuring transmit (send) and receive parameters
Communication blocks (for example, TSEND_C and TRCV_C) are used to establish
connections between two CPUs. Before the CPUs can engage in PROFINET
communications, you must configure parameters for transmitting (or sending) messages and
receiving messages. These parameters dictate how communications operate when
messages are being transmitted to or received from a target device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
919
Communication
11.2 PROFINET
Configuring the TSEND_C instruction transmit (send) parameters
TSEND_C instruction
The TSEND_C instruction (Page 837) creates a communications connection to a partner
station. The connection is set up, established, and automatically monitored until it is
commanded to disconnect by the instruction. The TSEND_C instruction combines the
functions of the TCON, TDISCON and TSEND instructions.
From the Device configuration in STEP 7, you can configure how a TSEND_C instruction
transmits data. To begin, you insert the instruction into the program from the
"Communications" folder in the "Instructions" task card. The TSEND_C instruction is
displayed, along with the Call options dialog where you assign a DB for storing the
parameters of the instruction.
You can assign tag memory locations to the inputs and outputs, as shown in the following
figure:
S7-1200 Programmable controller
920
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Configuring General parameters
You specify the parameters in the Properties configuration dialog of the TSEND_C
instruction. This dialog appears near the bottom of the page whenever you have selected
any part of the TSEND_C instruction.
Configuring the TRCV_C instruction receive parameters
TRCV_C instruction
The TRCV_C instruction (Page 837) creates a communications connection to a partner
station. The connection is set up, established, and automatically monitored until it is
commanded to disconnect by the instruction. The TRCV_C instruction combines the
functions of the TCON, TDISCON, and TRCV instructions.
From the CPU configuration in STEP 7, you can configure how a TRCV_C instruction
receives data. To begin, insert the instruction into the program from the "Communications"
folder in the "Instructions" task card. The TRCV_C instruction is displayed, along with the
Call options dialog where you assign a DB for storing the parameters of the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
921
Communication
11.2 PROFINET
You can assign tag memory locations to the inputs and outputs, as shown in the following
figure:
Configuring the General parameters
You specify the parameters in the Properties configuration dialog of the TRCV_C instruction.
This dialog appears near the bottom of the page whenever you have selected any part of the
TRCV_C instruction.
11.2.12
Configuring a CPU and PROFINET IO device
11.2.12.1
Adding a PROFINET IO device
Adding a PROFINET IO device
In the "Devices and networks" portal, use the hardware catalog to add PROFINET IO
devices.
Note
To add a PROFINET IO device, you can use STEP 7 Professional or Basic, V11 or greater.
For example, expand the following containers in the hardware catalog to add an ET 200SP
IO device: Distributed I/O, ET 200SP, Interface modules, and PROFINET. You can then
select the interface module from the list of ET 200SP devices (sorted by part number) and
add the ET 200SP IO device.
Table 11- 52 Adding an ET 200SP IO device to the device configuration
Insert the IO device
Result
S7-1200 Programmable controller
922
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
You can now connect the PROFINET IO device to the CPU:
1. Right-click the "Not assigned" link on the device and select "Assign new IO controller"
from the context menu to display the "Select IO controller" dialog.
2. Select your S7-1200 CPU (in this example, "PLC_1") from the list of IO controllers in the
project.
3. Click "OK" to create the network connection.
You can also go to the "Devices and networks" portal and use the "Network view" to create
the network connections between the devices in your project:
1. To create a PROFINET connection, click the green (PROFINET) box on the first device,
and drag a line to the PROFINET box on the second device.
2. Release the mouse button and your PROFINET connection is joined.
Refer to "Device Configuration: Configuring the CPU for communication" (Page 179) for
more information.
11.2.12.2
Assigning CPUs and device names
Assigning CPUs and device names
Network connections between the devices also assign the PROFINET IO device to the CPU,
which is required for that CPU to control the device. To change this assignment, click the
PLC Name shown on the PROFINET IO device. A dialog box opens that allows the
PROFINET IO device to be disconnected from the current CPU and reassigned or left
unassigned, if desired.
The devices on your PROFINET network must have an assigned name before you can
connect with the CPU. Use the "Network view" to assign names to your PROFINET devices
if the devices have not already been assigned a name or if the name of the device is to be
changed. Right-click the PROFINET IO device and select "Assign device name" to do this.
For each PROFINET IO device, you must assign the same name to that device in both the
STEP 7 project and to the PROFINET IO device in the PROFINET network. (You can use
either the STEP 7 "Online & diagnostics" tool or the PRONETA commissioning,
configuration, and diagnostics tool to assign the device name in the PROFINET network.) If
a name is missing or does not match in either location, the PROFINET IO data exchange
mode will not run. Refer to "Online and diagnostic tools: Assigning a name to a PROFINET
device online (Page 1314)" for more information.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
923
Communication
11.2 PROFINET
11.2.12.3
Assigning Internet Protocol (IP) addresses
Assigning the IP addresses
In a PROFINET network, each device must also have an Internet Protocol (IP) address. This
address allows the device to deliver data on a more complex, routed network:
● If you have programming or other network devices that use an on-board adapter card
connected to your plant LAN or an Ethernet-to-USB adapter card connected to an
isolated network, you must assign IP addresses to them. Refer to "Assigning IP
addresses to programming and network devices" (Page 810) for more information.
● You can also assign an IP address to a CPU or network device online. This is particularly
useful in an initial device configuration. Refer to "Assigning an IP address to a CPU
online" (Page 813) for more information.
● After you have configured your CPU or network device in your project, you can configure
parameters for the PROFINET interface, to include its IP address. Refer to "Configuring
an IP address for a CPU in your project" (Page 814) for more information.
11.2.12.4
Configuring the IO cycle time
Configuring the IO cycle time
A PROFINET IO device is supplied with new data from the CPU within an "IO cycle" time
period. The update time can be separately configured for each device and determines the
time interval in which data is transmitted from the CPU to and from the device.
STEP 7 calculates the "IO cycle" update time automatically in the default setting for each
device of the PROFINET network, taking into account the volume of data to be exchanged
and the number of devices assigned to this controller. If you do not want to have the update
time calculated automatically, you can change this setting.
You specify the "IO cycle" parameters in the "Properties" configuration dialog of the
PROFINET IO device. This dialog appears near the bottom of the page whenever you have
selected any part of the instruction.
In the "Device view" of the PROFINET IO device, click the PROFINET port. In the
"PROFINET Interface" dialog, access the "IO cycle" parameters with the following menu
selections:
● "Advanced options"
● "Realtime settings"
● "IO cycle"
Define the IO cycle "Update time" with the following selections:
● To have a suitable update time calculated automatically, select "Automatic".
● To set the update yourself, select "Can be set" and enter the required update time in ms.
S7-1200 Programmable controller
924
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Table 11- 53 Configuring the ET 200SP PROFINET IO cycle time
ET 200SP PROFINET IO device
ET 200SP PROFINET IO cycle dialog
① PROFINET port
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
925
Communication
11.2 PROFINET
11.2.13
Configuring a CPU and PROFINET I-device
11.2.13.1
I-device functionality
The "I-device" (intelligent IO device) functionality of a CPU facilitates data exchange with an
IO controller and operation of the CPU as intelligent preprocessing unit of sub processes, for
example. The I-device is linked as an IO device to a "higher-level" IO controller.
The pre-processing is handled by the user program on the CPU. The process values
acquired in the centralized or distributed (PROFINET IO or PROFIBUS DP) I/O are preprocessed by the user program and made available through a PROFINET IO interface to the
CPU of a higher-level station.
"I-device" naming conventions
In the remainder of this description, a CPU or a CP with I-device functionality is simply called
an "I-device".
S7-1200 Programmable controller
926
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.13.2
Properties and advantages of the I-device
Fields of application
Fields of application of the I-device:
● Distributed processing:
A complex automation task can be divided into smaller units/subprocesses. This results
in manageable processes which lead to simplified subtasks.
● Separating subprocesses:
Complicated, widely distributed and extensive processes can be subdivided into several
subprocesses with manageable interfaces by using I-devices. These subprocesses can
be stored in individual STEP 7 projects if necessary, which can later be merged to form
one master project.
● Know-how protection:
Components can only be delivered with a GSD file for the I-device interface description
instead of with a STEP 7 project. The user can protect his program since it no longer has
to be published.
Properties
Properties of the I-device:
● Unlinking STEP 7 projects:
Creators and users of an I-device can have completely separated STEP 7 automation
projects. The GSD file forms the interface between the STEP 7 projects. This allows a link
to standard IO controllers through a standardized interface.
● Real-time communication:
The I-device is provided with a deterministic PROFINET IO system through a
PROFINET IO interface.
Advantages
The I-device has the following advantages:
● Simple linking of IO controllers
● Real-time communication between IO controllers
● Relieving the IO controller by distributing the computing capacity to I-devices.
● Lower communications load by processing process data locally.
● Manageable, due to processing of subtasks in separate STEP 7 projects
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
927
Communication
11.2 PROFINET
11.2.13.3
Characteristics of an I-device
An I-device is included in an IO system like a standard IO device.
I-device without lower-level PROFINET IO system
The I-device does not have its own distributed I/O. The configuration and parameter
assignment of the I-devices in the role of an IO device is the same as for a distributed I/O
system (for example, ET 200).
S7-1200 Programmable controller
928
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
I-device with lower-level PROFINET IO system
Depending on the configuration, an I-device can also be an IO controller on a PROFINET
interface in addition to having the role of an IO device.
This means that the I-device can be part of a higher-level IO system through its PROFINET
interface and as an IO controller can support its own lower-level IO system.
The lower-level IO system can, in turn, contain I-devices (see figure below). This makes
hierarchically structured IO systems possible.
In addition to its role as IO controller, an I-device can also be used through a PROFIBUS
interface as DP master for a lower-level PROFIBUS system.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
929
Communication
11.2 PROFINET
Example: I-device as IO device and IO controller
The I-device as IO device and IO controller is explained based on the example of a print
process. The I-device controls a unit (a subprocess). One unit is used, for example, to insert
additional sheets such as flyers or brochures in a package of printed material.
Unit 1 and unit 2 each consist of an I-device with centralized I/O. The I-device along with the
distributed I/O system (for example, ET 200) forms unit 3.
The user program on the I-device is responsible for preprocessing the process data. For this
task, the user program of the I-device requires default settings (for example, control data)
from the higher-level IO controller. The I-device provides the higher-level IO controller with
the results (for example, status of its subtask).
S7-1200 Programmable controller
930
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.13.4
Data exchange between higher- and lower-level IO system
Transfer areas are an interface to the user program of the I-device CPU. Inputs are
processed in the user program and outputs are the result of the processing in the user
program.
The data for communication between IO controller and I-device is made available in the
transfer areas. A transfer area contains an information unit that is exchanged consistently
between IO controller and I-device. You can find more information on configuration and use
of transfer areas in the section "Configuring the I-device".
The next figure shows the data exchange between the higher- and lower-level IO system.
The individual communication relations are explained below based upon the numbers:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
931
Communication
11.2 PROFINET
①
②
Data exchange between higher-level IO controller and normal IO-device
In this way, the IO controller and IO devices exchange data through PROFINET.
Data exchange between higher-level IO controller and I-device
In this way, the IO controller and the I-device exchange data through PROFINET.
The data exchange between a higher-level IO controller and an I-device is based upon the
conventional IO controller / IO device relationship.
For the higher-level IO controller, the transfer areas of the I-devices represent submodules of a
pre-configured station.
③
④
The output data of the IO controller is the input data of the I-device. Analogously, the input data
of the IO controller is the output data of the I-device.
Transfer relationship between the user program and the transfer area
In this way, the user program and the transfer area exchange input and output data.
Data exchange between the user program and the I/O of the I-device
In this way, the user program and the centralized / distributed I/O exchange input and output
data.
S7-1200 Programmable controller
932
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
⑤
Data exchange between the I-device and a lower-level IO device
In this way, the I-device and its IO devices exchange data. The data transfer is through
PROFINET.
11.2.13.5
Configuring the I-device
There are basically two possibilities for configuration:
● Configuration of an I-device within a project
● Configuration of an I-device that is used in another project or in another engineering
system.
STEP 7 allows you to configure an I-device for another project or for another engineering
system by exporting a configured I-device to a GSD file. You import the GSD file in other
projects or engineering systems as with other GSD files. The transfer areas for the data
exchange, among other data, are stored in this GSD file.
Note
When you use the S7-1200 as a shared I-device and as a controller, ensure that you
increase the PROFINET I-device and PROFINET IO Update times to alleviate the
communications performance impact. The system is very stable and works well when you
select 2 ms for the Update time of a single PROFINET I-device time and you select 2 ms for
the Update time of a single PROFINET IO time.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
933
Communication
11.2 PROFINET
Configuration of an I-device within a project
1. Drag-and-drop a PROFINET CPU from the hardware catalog into the network view.
2. Drag-and-drop a PROFINET CPU, which can also be configured as an IO device, from
the hardware catalog into the network view. This device is configured as an I-device (for
example, CPU 1215C).
3. Select the PROFINET interface for the I-device.
4. In the Inspector window in the area navigation choose "Operating mode" and select the
check box "IO device".
5. Now you have the option of choosing the IO controller in the "Assigned IO controller"
drop-down list.
Once you have chosen the IO controller, the networking and the IO system between both
devices are displayed in the network view.
6. With the "Parameter assignment of PN interface by higher-level IO controller" check box,
you specify whether the interface parameters will be assigned by the I-device itself or by
a higher-level IO controller.
If you operate the I-device with a lower-level IO system, then the parameters of the Idevice PROFINET interface (for example, port parameter) cannot be assigned with the
higher-level IO controller.
S7-1200 Programmable controller
934
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
7. Configure the transfer areas. The transfer areas are found in the area navigation section
"I-device communication":
– Click in the first field of the "Transfer area" column. STEP 7 assigns a default name
which you can change.
– Select the type of communication relation: you can currently only select CD or F-CD.
– Addresses are automatically preset; you can correct addresses if necessary, and
determine the length of the transfer area which is to be consistently transferred.
8. A separate entry is created in the area navigation for each transfer area. If you select one
of these entries, you can adjust the details of the transfer area, or correct them and
comment on them.
Note
If you configure an S7-1200 as an I-device, the maximum size of a transfer area is 1024
input or output bytes. There are possible constraining factors depending on local I/O as well
as address space limitations on the controlling device.
Configuring an I-device with a GSD file
If you use an I-device in another project, or if the I-device is used in another engineering
system, then configure the higher-level IO controller and the I-device as described above.
However, click on the "Export" button after configuring the transfer areas so a new GSD file
is created from the I-device. This GSD file represents the configured I-device in other
projects.
The "Export" button is found in the "I-device communication" section of the Inspector
window.
The hardware configuration is compiled and the export dialog opened.
Assign a name for the I-device proxy as well as a description in the fields provided. Click the
"Export" button to complete your process.
Finally, import the GSD file, for example, in another project.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
935
Communication
11.2 PROFINET
11.2.14
Shared devices
11.2.14.1
Shared device functionality
Numerous IO controllers are often used in larger or widely distributed systems.
Without the "Shared Device" function, each I/O module of an IO device is assigned to the
same IO controller. If sensors that are physically close to each other must provide data to
different IO controllers, several IO devices are required.
The "Shared Device" function allows the modules or submodules of an IO device to be
divided up among different IO controllers. This allows flexible automation concepts. You
have, for example, the possibility of combining I/O modules lying near each other into an IO
device.
①
②
PROFINET
Logical assignment
Principle
Access to the submodules of the shared device is then divided up among the individual IO
controllers. Each submodule of the shared device is assigned exclusively to one IO
controller.
S7-1200 Programmable controller
936
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Requirement (GSD configuration)
● STEP 7 V12 Service Pack 1 or higher
● S7-1200 CPU with firmware of V4.1 or later as IO controller
● IO device supports the shared device function, e.g. interface module IM 155-5 PN ST
● GSD file for configuring the IO device is installed
● An S7-1200 CPU configured as an I-device supports the Shared Device functionality. You
must export the PROFINET GSD file for the I-device from STEP 7 (as of V5.5) and then
import it into STEP 7 (TIA Portal).
Configuring the access
The IO device must be present in several projects so that the modules or submodules of an
IO device can be assigned to different IO controllers. A separate project is required for each
IO controller.
You use the "Shared device" parameter of the interface module to determine the modules or
submodules to which the IO controller has access:
● If the local IO controller has access to the configured module, select the name of the IO
controller from the list.
● If the IO controller from a different project and not the local IO controller is to have access
to the configured module, select the entry "---".
The configuration is consistent regarding access if each module or submodule in exactly one
project is assigned to an IO controller.
Module or submodule is assigned to another IO controller
The paragraph below describes the consequences of the "---" setting of the "Shared device"
parameter from the point of view of the local IO controller.
In this case, the local IO controller does not have access to the module configured in this
way. Specifically, this means:
● No data exchange with the module or submodule
● No reception of alarms or diagnostics, which means no display of the diagnostics status
in the online view
● No parameter assignment of the module or submodule
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
937
Communication
11.2 PROFINET
Setting of the real-time properties
STEP 7 calculates the communication load and thus the resulting update times. You must
enter the number of project-external IO controllers in the project in which the PROFINET
interface of the shared device is assigned to the IO controller so that a calculation is possible
with shared device configurations.
The maximum possible number of IO controllers for the shared device depends on the
device. This number is stored in the GSD file of the shared device.
You can set a very short send clock (minimum of 1 ms) with an S7-1200 CPU as IO
controller. The send clock can be shorter than the shortest send clock supported by the
shared device. In this case, the shared device is operated by the IO controller with a send
clock that it supports (send clock adaptation).
Example: A CPU supports send clocks starting from 1 ms. A configured IO device supports
send clocks starting at 1.25 ms; another IO device supports send clocks starting at 1 ms. In
this case, you have the option of setting the short send clock of 1 ms for the CPU. The CPU
operates the "slow" IO device with the send clock of 1.25 ms.
Rules for the configuration
● IO controllers that use the shared device are created in different projects. In each project,
care must be taken that the shared device is configured identically in each station. Only
one IO controller may ever have full access to a submodule. Inconsistencies in the
configuration result in a failure of the shared device.
● I/O addresses of a module or submodule can only be edited if a module or submodule is
assigned to the IO controller in the same project.
● The shared device must have the same IP parameters and the same device name in
each project.
● The send clock must be identical for all IO controllers that have access to the shared
device.
● The S7 subnet ID of the subnet to which the shared device is connected must be identical
in all projects.
● The following functions are only available if the PROFINET interface of the shared device
is assigned to the local IO controller:
– Prioritized startup
– Parameter assignment of the port properties
S7-1200 Programmable controller
938
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Boundary conditions
The following boundary conditions result because a shared device configuration is
distributed across several projects:
● The addresses of modules or submodules that are not assigned to this IO controller are
missing in the address overview of each IO controller that has access to a shared device.
● The modules or submodules that are not assigned are not taken into consideration in the
configuration limit calculation for the shared device during the consistency check. For this
reason, you must verify for yourself that the maximum number of submodules or the
maximum amount of cyclic IO data for the shared device will not be exceeded. For
information on the maximum quantities, refer to the documentation for the devices you
are using.
● Configuration errors such as the assignment of a module or submodule to several IO
controllers are not detected in STEP 7.
● CPUs that are loaded with a shared device configuration do not have any information on
whether the IO device is a shared device. Modules or submodules that are assigned to
other IO controllers and therefore other CPUs are missing in the loaded configuration.
These modules or submodules are therefore displayed neither in the CPU web server nor
in the CPU display.
11.2.14.2
Example: Configuring a shared device (GSD configuration)
This example describes how to configure a distributed I/O system as a shared device with
STEP 7 V13 SP1 or higher.
A "distributed" configuration with different engineering tools for different IO controller families
is possible. The procedure described below is based on STEP 7 as of V13 SP1 and is
limited to configuration with two IO controllers of the S7-1200 series that share one shared
device.
The example creates two projects with one IO controller each:
● Controller1
● Controller2
You must create the shared device in both projects, even though it is physically one and the
same IO device.
Requirements
● STEP 7 V13 SP1 or higher
● IO device supports shared device functionality (for example, ET 200SP IM 155-6 PN HF
V3.1).
● GSD file for configuring the IO device as a shared device is installed.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
939
Communication
11.2 PROFINET
Procedure: Creating project 1
To create the first project with a shared device, follow these steps:
1. Start STEP 7.
2. Create a new project with the name "Controller1".
3. Insert a CPU 1215C from the hardware catalog in the network view. Name it
"Controller1".
4. Insert an IO device with the "Shared Device" function (for example, an ET 200SP) from
the hardware catalog (hardware catalog: Other field devices > PROFINET IO > I/O).
5. Assign the IO controller "Controller1" to the IO device.
6. Double-click the IO device and insert all required modules and submodules from the
hardware catalog in the device overview table.
7. Assign the module parameters.
8. Save the project.
S7-1200 Programmable controller
940
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Procedure: Creating project 2
To create the second project with a shared device, follow these steps:
1. Start STEP 7 once again.
A new instance of STEP 7 opens.
2. In the new instance, create a new project with the name "Controller2".
3. Insert a CPU 1215C in the network view. Name it "Controller2".
4. Copy the IO device from the project "Controller1" and insert it in the network view of
project "Controller2".
5. Assign the IO controller "Controller2" to the IO device.
6. Save the project.
Both projects now have an identically structured IO device that must be configured in the
next step for the different types of IO controller access.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
941
Communication
11.2 PROFINET
Procedure: Configuring access to the shared device
The modules and submodules you insert in the shared device are automatically assigned to
the local CPU. To change the assignment, follow these steps:
1. Select the interface module in the network or device view of project "Controller1".
2. Select the "Shared Device" area in the Inspector window.
A table shows which CPU has access to the respective module or submodule for all
configured modules. The default setting is that the local CPU has access to all modules
and submodules.
3. Keep the "Controller1" setting for all modules and submodules that are to remain in the
address range of the local CPU.
Select the setting "---" for all modules and submodules that are to be located in the
address range of the CPU from the "Controller2" project (Controller2). This means that an
IO controller outside the project is to have access to the module or submodule.
4. Select the interface module in the network or device view of project "Controller2".
5. Select the "Shared Device" area in the Inspector window.
A table shows which CPU has access to the respective module or submodule for all
configured modules.
S7-1200 Programmable controller
942
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
6. Select the setting "---" for all modules and submodules that are to be located in the
address range of the CPU from the "Controller1" project (Controller1).
7. Finally, check whether the settings for access are "complementary" for each module or
submodule in both projects. This means that if the local CPU has access in one project,
the option "---" must be set in the other project and vice versa.
Note: The option "---" for the PROFINET interface and therefore for the ports makes the
associated parameters read-only and not changeable. Parameters of the PROFINET
interface and port parameters can only be edited in the project in which the PROFINET
interface is assigned to the local CPU. The ports can be interconnected in both projects
regardless of this.
8. Check whether the same IP address parameters and device name are set for the shared
device in all projects.
Check whether the same S7 subnet ID is set in all projects for the subnet to which the
shared device is connected (subnet properties, "General" area in the Inspector window).
Note
If you make changes to the shared device: Make the same changes in each project on the
shared device. Make sure that only one IO controller has access to a module or submodule.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
943
Communication
11.2 PROFINET
Procedure: Adjusting the real-time settings
To ensure that all IO controllers and shared devices are operated with the appropriate send
clock and that the update times are calculated correctly based on the communication load,
you must adjust and check the following settings:
1. Select the project whose IO controllers have access to the PROFINET interface and the
ports of the shared device.
2. Select the interface module of the shared device in the network view.
3. In the Inspector window, navigate to the "PROFINET interface > Advanced options >
Real time settings > IO cycle" area.
4. In the "Shared device" area, set the number of project-external IO controllers. The
maximum number depends on the IO device (specification in GSD file).
5. You must set the same send clock for each IO controller that has access to modules and
submodules of the shared device:
● If you configure the IO controller with STEP 7 (TIA Portal):
– Open the corresponding project.
– Select the PROFINET interface of the IO controller.
– Select the "Advanced options > Real time settings > IO communication" area in the
Inspector window and set the shared send clock.
● If you configure the IO controller with a different engineering tool:
– Select the PROFINET interface of the shared device in STEP 7 (TIA Portal) and read
out the send clock on the shared device ("Advanced options > Real time settings"
area).
– Enter the read send clock in the engineering tool.
Note
If you configure all IO controllers that have access to the shared device in STEP 7
(TIA Portal), you can set shorter send clocks on the IO controller than supported by the
shared device (send clock adaptation).
Compiling and loading
You must compile the configurations for the different IO controllers and load them to the
CPUs one after the other.
Due to the distributed configuration with separate projects, STEP 7 does not output
consistency errors in the case of incorrect access parameter assignment. These are
examples of incorrect access parameter assignment:
● Several IO controllers have access to the same module
● IP address parameters or send clocks are not identical
These errors do not show up until controller operation and are output as configuration errors.
S7-1200 Programmable controller
944
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.14.3
Example: Configuring an I-device as a shared device
This example describes how to configure an S7-1200 as an I-device with STEP 7 Version
V13 SP1 or higher and then use it in two projects as a shared device.
A "distributed" configuration with different engineering tools for different IO controller families
is possible. The procedure described below is based on STEP 7 V13 SP1 and is limited to a
configuration with two IO controllers of the S7-1200 family that share the transfer areas of an
I-device as a shared device. The I-device itself is a CPU 1215C.
The example creates three projects with one IO controller each:
● S7-1200-I-Device
● Controller1
● Controller2
You use the S7-1200-I-Device project to configure the I-device. You use the PROFINET
GSD variant of S7-1200-I-Device in the Controller1 and Controller2 projects in order to
assign the transfer areas in the respective higher-level IO controller.
Shared I-device concept
The shared I-device concept requires a minimum of three separate projects:
● I-device project: You configure and program an I-device to perform a particular
automation task. You define transfer areas as the I/O interface for the higher level
controllers and assign these transfer areas to different IO controllers. For the connection
to higher-level IO controllers, you provide a PROFINET GSD file and use the transfer
areas to access the I-device.
● Controllers that share the I-device (two projects): You use the I-device as a PROFINET
GSD variant during configuration of the PROFINET IO system and, in this process,
specify the I/O addresses under which the IO controllers access the transfer areas.
Note
If you configure an S7-1200 as an I-device, the maximum size of a transfer area is 1024
input or output bytes. There are possible constraining factors depending on local I/O as well
as address space limitations on the controlling device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
945
Communication
11.2 PROFINET
I-device
You assign the following parameters for an S7-1200 CPU as an I-device:
● Centralized and distributed I/O
● Desired transfer areas
● Number of IO controllers having access to this I-device (always greater than 1 for a
shared device)
Note
You configure the I-device without a higher-level IO controller. As a result, you can only use
the local I/O addresses of the transfer area (corresponds with the "Address in the I-device")
to create the user program for editing the addresses from the transfer area. You download
the I-device, completely configured except for the connection to the higher-level IO
controller, to the S7-1200 CPU.
You export a PROFINET GSD file from the I-device configuration.
Controllers that share the I-device
You must install the PROFINET GSD file created from the I-device configuration in all
engineering systems that you use in configuring a PROFINET IO system with this shared
I-device. If you configure all uses of this I-device with STEP 7 V13 SP1, it is sufficient to
install the GSD file in STEP 7.
You configure the I-device as a GSD variant on the PROFINET IO system in the projects
involved. In STEP 7 V13 SP1, you find this I-device under "Other field devices > PROFINET
IO > PLCs & CPs" following installation.
In each of the projects involved, you assign transfer areas exclusively to the higher-level IO
controllers (default setting: all). You set the other transfer areas to "---" (not assigned). When
you do so, the local IO controller cannot access this transfer area, and you can assign the
transfer area to another IO controller in another project.
Requirements
● STEP 7 V13 SP1 or higher
● IO device supports shared device functionality (for example, ET 200SP IM 155-6 PN HF
V3.1).
● GSD file for configuring the IO device as a shared device is installed.
S7-1200 Programmable controller
946
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Procedure: Creating the S7-1200-I-device project
To create the project with a shared I-device, follow these steps:
1. Start STEP 7.
2. Create a new project with the name "S7-1200-I-device".
3. Insert a CPU 1215C from the hardware catalog in the network view. Assign the name
"S7-1200-I-device".
4. Double-click the IO device and configure all required modules and submodules.
5. Assign the module parameters. In particular, you must configure the following settings for
the CPU in the area of the PROFINET interface [X1]:
– Enable the "IO device" option in the "Operating mode" area.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
947
Communication
11.2 PROFINET
– Configure the transfer areas in the "Operating mode" > "I-device configuration" area.
The "Address in IO controller" column remains empty because no IO controller is
assigned.
Note: To change an input area to an output area, and vice versa, you must navigate to
the area of the corresponding transfer area.
– Select the number of IO controllers (at least two) that will access the shared I-device
during operation ("Operating mode" > "Real time settings" area, "Shared Device"
area).
6. Save the project.
7. Click the "Export" button ("Mode" > "I-device configuration" area, "Export general station
description file (GSD)" section). If you do not change the name in the Export dialog, the
GSD file uses an assigned format name (for example, "GSDML-V2.31-#SiemensPreConf_S7-1200-I-Device-20130925-123456").
S7-1200 Programmable controller
948
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Procedure: Creating the Controller1 project
To create the first project with a shared I-device, follow these steps:
1. Start STEP 7.
2. Install the PROFINET GSD file from the export of the I-device CPU (S7-1200-I-Device).
3. Create a new project with the name "Controller1".
4. Insert the CPU 1215C in the network view. The name of the CPU should be "Controller1".
5. Insert the I-device from the hardware catalog (Hardware catalog: Other field devices >
PROFINET IO > PLCs & CPs).
6. Assign the IO controller "Controller1" to the I-device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
949
Communication
11.2 PROFINET
7. Select the "Shared device" area in the properties of the I-device:
– In the table, all transfer areas and the PROFINET interface are assigned to the local
IO controller (Controller1).
– Define the transfer areas to which the Controller1 CPU should not have access. Select
the "---" entry for these areas. These transfer areas are provided for Controller2.
S7-1200 Programmable controller
950
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
8. You can adapt the addresses from the Device view of the IO controller in the Device
overview. To open the device overview, double-click the I-device.
9. Save the project.
Procedure - Creating the Controller2 project
To create the second project with a shared device, follow these steps:
1. Start STEP 7 once again.
A new instance of STEP 7 opens.
2. In the new instance, create a new project with the name "Controller2".
3. Insert the CPU 1215C in the network view. Assign the name "Controller2".
4. Insert the I-device from the hardware catalog (Hardware catalog: Other field devices >
PROFINET IO > PLCs & CPs).
5. Assign the IO controller "Controller2" to the I-device.
6. Adapt the access to the transfer areas as in the Controller1 project. Ensure that no
duplicate assignments result.
7. Adapt the parameters of the subnet and PROFINET interface. Because the shared Idevice involves the same device in different projects, these data must match.
8. Save the project.
Both projects now have an identically configured shared I-device. The IO controller access
and the parameters of the PROFINET interface should still be checked in the different
projects during the next step.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
951
Communication
11.2 PROFINET
Summary - Assigning parameters for access to the shared device
The transfer areas are automatically assigned to the local IO controller. To change the
assignment, follow these steps:
1. Click the "S7-1200-I-Device" device in the network view of the "Controller1" project, and
select the "Shared device" area.
2. A table shows which CPU has access to each of the configured transfer areas. The
default setting is that the local CPU has access to all modules and submodules.
3. Keep the setting "Controller1" for all transfer areas that are to remain in the address
range of the local CPU.
Select the setting "---" for all transfer areas that are to be located in the address range of
the "Controller2" CPU from the "Controller2" project. This means that an IO controller
outside the project is to have access to the transfer area.
4. Follow the same procedure for the remaining projects.
5. Finally, check whether the settings for access are "complementary" for each module or
submodule in both projects. This means that if the local CPU has access in one project,
the option "---" must be set in the other project and vice versa.
Note: The option "---" for the PROFINET interface and therefore for the ports makes the
associated parameters read-only and not changeable. Parameters of the PROFINET
interface and port parameters can only be edited in the project in which the PROFINET
interface is assigned to the local CPU. The ports can be interconnected in both projects
regardless of this.
6. Check whether the same IP address parameters and device name are set for the shared
device in all projects.
Check whether the same S7 subnet ID is set in all projects for the subnet to which the
shared device is connected (subnet properties, "General" area in the Inspector window).
Note
If you make changes to the I-device (for example, change the number or length of the
transfer areas), export the I-device as a GSD file again. Re-install the GSD file in each
project that uses the I-device as a shared device. Make sure that only one IO controller has
access to a transfer area.
Note
When you use the S7-1200 as a shared I-device and as a controller, ensure that you
increase the PROFINET I-device and PROFINET IO Update times to alleviate the
communications performance impact. The system is very stable and works well when you
select 2 ms for the Update time of a single PROFINET I-device time and you select 2 ms for
the Update time of a single PROFINET IO time.
You specify the "IO cycle" parameters in the "Properties" configuration dialog of the
PROFINET I-device or IO. Refer to "Configuring the IO cycle time" (Page 924) for further
information.
S7-1200 Programmable controller
952
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
Procedure - Adjusting the real-time settings
To ensure that all IO controllers and shared devices are operated with the appropriate send
clock and that the update times are calculated correctly based on the communication load,
you must adjust and check the following settings:
1. You must set the same send clock for each IO controller that has access to modules and
submodules of the shared device:
● If you configure the IO controller with STEP 7 (TIA Portal), perform these steps:
– Open the corresponding project.
– Select the PROFINET interface of the IO controller.
– Select the "Advanced options > Real time settings > IO communication" area in the
Inspector window and set the shared send clock.
● If you configure the IO controller with a different engineering tool, perform these steps:
– Select the PROFINET interface of the shared device in STEP 7 (TIA Portal) and read
out the send clock on the shared device ("Advanced options > Real time settings"
area)
– Enter the read send clock in the engineering tool.
Note
If you configure all IO controllers that have access to the shared I-device in STEP 7
(TIA Portal), you can set shorter send clocks on the IO controller than supported by the
shared device (send clock adaptation).
Compiling and downloading
You must compile the configurations for the different IO controllers and download them to
the CPUs one after the other.
Due to the distributed configuration with separate projects, STEP 7 does not output
consistency errors in the case of incorrect access parameter assignment. These are
examples of incorrect access parameter assignment:
● Several IO controllers have access to the same module.
● IP address parameters or send clocks are not identical.
These errors do not show up until controller operation and are output as configuration errors.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
953
Communication
11.2 PROFINET
11.2.15
Media Redundancy Protocol (MRP)
The following V4.2 S7-1200 CPUs support operations as an MRP client, but do not fulfill the
MRP manager role:
● CPU 1215C
● CPU 1217C
● CPU 1215FC
The three S7-1200 CPUs all have two PN ports which are required to support the MRP
protocol and the configuration parameters used to initialize MRP client operation.
11.2.15.1
Media redundancy with ring topologies
In order to increase the network availability of an Industrial Ethernet network with optical or
electrical linear bus topologies, you can convert a linear bus topology to a ring topology by
joining the ends together.
Devices in a ring topology can be IO devices, IO controllers, external switches, and/or the
integrated switches of communication modules.
To set up a ring topology with media redundancy, you need to bring together the two free
ends of a linear bus topology in one device. Closing the linear bus topology to form a ring is
achieved with two ports (ring ports) of a device in the ring. One device of the resulting ring
then takes over the role of the MRP manager. All other devices in the ring are MRP clients.
①
②
③
MRP manager
Test frames
MRP clients
The ring ports of a device are the ports that establish the connection to the two neighboring
devices in the ring topology. The ring ports are selected and set in the configuration of the
relevant device (is also preset, if applicable).
S7-1200 Programmable controller
954
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
How media redundancy works in a ring topology
The data paths between the individual devices are automatically reconfigured if the ring is
interrupted at any point. The devices are available again after reconfiguration.
In the MRP manager, one of the two ring ports is blocked in uninterrupted network operation
for normal communication so that no data frames are circulated. In terms of data
transmission, the ring topology is a linear bus topology. The MRP manager monitors the ring
for interruptions. It does this by sending test frames both from ring port 1 and ring port 2. The
test frames run round the ring in both directions until they arrive at the other ring port of the
MRP manager.
An interruption of the ring can be caused by loss of the connection between two devices or
by failure of a device in the ring.
If the test frames of the MRP manager no longer arrive at the other ring port during an
interruption of the ring, the MRP manager connects its two ring ports. This substitute path
once again restores a functioning connection between all remaining devices in the form of a
linear bus topology.
The time between the ring interruption and restoration of a functional linear topology is
known as the reconfiguration time.
As soon as the interruption is eliminated, the original transmission paths are established
again, the two ring ports of the MRP manager are disconnected, and the MRP clients
informed of the change. The MRP clients then use the original paths again to the other
devices.
Media redundancy method
The standard method of media redundancy in SIMATIC is Media Redundancy Protocol
(MRP) with a typical reconfiguration time of 200 ms. Up to 50 devices can participate per
ring.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
955
Communication
11.2 PROFINET
11.2.15.2
Using Media Redundancy Protocol (MRP)
The "MRP" process works in conformity with Media Redundancy Protocol (MRP), which is
specified in IEC 61158 Type 10 "PROFINET".
Requirements
The following requirements must be met for error-free operation with MRP:
● The ring in which you want to use MRP may only consist of devices that support this
function.
● "MRP" must be activated for all devices in the ring.
● All devices must be interconnected using their ring ports.
● At least one MRP manager (role "Manager (Auto)") must be available.
● The ring must contain not more than 50 devices. Otherwise, reconfiguration times of
greater than or equal to 200 ms can occur.
● All partner ports within the rings must have the identical settings.
Topology
The following schematic shows a possible topology for devices in a ring with MRP. The
devices inside the shaded oval are in the redundancy domain.
This is an example of a ring topology with MRP:
S7-1200 Programmable controller
956
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
The following rules apply to a ring topology with media redundancy using MRP:
● All devices in the ring belong to the same redundancy domain.
● One device in the ring has the role of a MRP manager.
● All other devices in the ring are MRP clients.
You can connect non MRP-compliant devices to the network through ports not configured as
ring ports. You can only do this with devices that have more than two ports (for example, a
SCALANCE X switch or a PC with a CP1616).
Boundary conditions
You can have the following communication possibilities:
● MRP and RT: RT operation is possible with the use of MRP.
Note
The RT communication is disrupted (station failure) if the reconfiguration time of the ring
is greater than the selected watchdog time of the IO device. You must select a watchdog
time greater than 200 ms for your IO devices. Refer to the "Watchdog time" section below
for further information.
● MRP and TCP/IP (TSEND, HTTP, ...): The TCP/IP communication with MRP is possible
because lost data packages are resent, if applicable.
● MRP and prioritized startup:
– If you configure MRP in a ring, you cannot use the "prioritized startup" function in
PROFINET applications on the devices involved.
– If you want to use the "prioritized startup" function, then you must disable MRP in the
configuration (the device cannot be part of the ring).
● MRP on PROFINET devices with more than two ports: If you operate a PROFINET
device with more than two ports in a ring, you should set a sync boundary on the ports
that are not in the ring. By setting the sync boundary, you define a boundary for a sync
domain. You cannot forward sync frames transmitted to synchronize devices within a
sync domain.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
957
Communication
11.2 PROFINET
Watchdog time
The watchdog time is the time interval that an IO controller or IO device permits, without
receiving IO data. If the IO device is not supplied by the IO controller with data within the
watchdog time, the device detects the missing frames and outputs substitute values. This is
reported in the IO controller as a station failure.
You can configure the watchdog time for PROFINET IO devices. Do not enter the watchdog
time directly, but as "Accepted number of update cycles when IO data is missing". The
resulting watchdog time is automatically calculated from the number of update cycles.
To assign the watchdog time, follow these steps:
1. Select the PROFINET interface of the IO device in the Network or Device view.
2. In the properties of the interface, navigate to: Advanced options > Realtime settings > IO
cycle
3. Select the required number of cycles from the drop-down list.
S7-1200 Programmable controller
958
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.15.3
Configuring media redundancy
All of the components in your application must support Media Redundancy Protocol (MRP).
Procedure
To configure media redundancy, proceed as follows:
1. Establish a ring by means of appropriate port interconnections (for example, in the
topology view).
2. Select a PROFINET device for which you want to configure media redundancy.
3. In the Inspector window, navigate to "PROFINET" interface [X1]">"Advanced
options">"Media redundancy".
4. Under "Media redundancy role", assign the "Manager (Auto)", "Client", or "Not device in
the ring" role to the device.
When you configure a ring in the TIA Portal Topology view, the TIA Portal automatically
sets the Media Redundancy role for you. If a device can be a Manager, the TIA Portal
sets the Media redundancy role as "Manager (Auto)". For the S7-1200, the Media
Redundancy role is automatically set to "Client".
Note
You cannot assign the "Manager (Auto)" media redundancy role to the S7-1200 CPU.
5. Repeat steps 2 to 4 for all PROFINET devices in the ring.
Or:
1. Highlight the PROFINET IO system in the network view.
2. Click on the PROFINET IO system.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
959
Communication
11.2 PROFINET
3. Navigate to the device of the required MRP domain in the inspector window.
4. For the PROFINET devices, set the "Manager (Auto)", "Client", or "Not device in the ring"
role.
Note
You cannot assign the "Manager (Auto)" MRP role to the S7-1200 CPU.
"Media redundancy" setting option: MRP role
Depending on the device used, the roles "Manager", "Manager (Auto)", "Client", and "Not
device in the ring" are available.
Rules:
● A ring can have only one device with the role of "Manager". No additional devices with the
role of "Manager" or "Manager (Auto)" are permissible. All other devices in the ring can
only have the role of "Client". Devices not in the ring can have the role "Not device in the
ring".
● If a ring has no device with the "Manager" role, the ring must at least have one device
with the role "Manager (Auto)". A ring can have any number of devices with the roles
"Client" and "Manager (Auto)".
Note
You cannot assign the "Manager" or "Manager (Auto)" MRP roles to the S7-1200 CPU.
S7-1200 Programmable controller
960
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
"Media redundancy" setting option: Ring port 1 and Ring port 2
Select one at a time those ports you want to configure as ring port 1 or ring port 2. The dropdown list box shows the selection of possible ports for each device type. If the ports are set
at the factory, then the fields are unavailable.
Note
Ring port configuration is not necessary in the S7-1200 because the S7-1200 CPU has only
two ports.
Diagnostic interrupts
If diagnostic interrupts to the MRP state are to be output in the local CPU, select the
"Diagnostic interrupts" check box. The following diagnostic interrupts can be configured:
● Wiring or port error:
The CPU generates diagnostic interrupts for the following errors in the ring ports:
– A neighbor of the ring port does not support MRP.
– A ring port is connected to a non-ring port.
– A ring port is connected to the ring port of another MRP domain.
● Interruption / return (MRP manager only):
If the ring is interrupted and the original configuration is returned, the CPU generates
diagnostic interrupts. If both of these interrupts occur within 0.2 seconds, this indicates an
interruption of the ring.
You can respond to these events in the user program by programming the appropriate
response in the diagnostic error interrupt OB (OB 82).
Note
Third-party devices as MRP manager
To assure error-free operation when a third party device is used as MRP manager in a ring,
you must assign the fixed role of "Client" to all other devices in the ring before you close the
ring. Otherwise, circulating data frames and network failure could occur.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
961
Communication
11.2 PROFINET
11.2.16
S7 routing
From the STEP 7 Network view, you can create a complex communication topology by
connecting devices in different S7 subnets. You can connect classic CPUs and CPs as well
as the latest S7 CPUs and CPs and can include HMIs and PC stations such as an OPC
server.
Once you decide which devices must communicate and establish the necessary connections
using STEP 7, the Engineering System (ES) can download the corresponding routing tables
to the various S7 routers as part of the hardware configuration. After you download the
routing tables to the various S7 routers, the ES or other communication partners can
communicate with each device even though the devices are on different S7 subnets. This is
possible because the CPUs and/or CPs, in between, act as S7 routers. The CPUs and/or
CPs forward incoming connection requests to the next S7 router until the connection request
reaches the targeted device, and the devices establish the S7 connection.
The CPU uses the write record mechanism to transfer the routing tables required by the CP
devices in the local base. The routing tables establish the route from one device to another
at the time of a connection request, which includes a remote S7 Subnet_ID. The device
receiving the connection request interrogates its routing table, finds the next station in the
path to the target S7 subnet, and forwards the connection request. Eventually, the
connection request reaches the intended target and the response traverses the route in the
reverse direction.
The S7-1200 CPUs have a single PN interface and up to three CP devices connected to the
local communication bus. Therefore, you have two options for routing within the S7-1200
station:
● Routing between the CPU and a CP
● Routing from one CP to another CP
Refer to S7-1200 CPs at Siemens Industry Online Support, Product Support for further
information on all S7-1200 CPs that support the S7 routing function. The CP 1243-1
(https://support.industry.siemens.com/cs/us/en/view/584459) is shown as an example CP
module search for S7 routing capabilities.
S7-1200 Programmable controller
962
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.16.1
S7 routing between CPU and CP interfaces
Since the S7-1200 CPUs are limited to a single PN interface, a stand-alone CPU cannot
serve the function of a router. You can never connect a stand-alone CPU to more than one
S7 subnet at a time. When you install CP modules in the local base of the CPU, you can
connect to multiple S7 subnets and utilize routing.
In the example system below, in order for PLC_1 to communicate with PLC_3, the
Engineering System (ES) must rout messages through PLC_2. The ES must download the
routing table for PLC_2, and PLC_2 must provide the routing table for the CP module in its
local base. With these routing tables in place, PLC_1 and PLC_3 can communicate with
each other, even though not directly connected.
In order to check routing from either S7 subnet to the other S7 subnet, PLC_1 must establish
a transport connection to PLC_3, and PLC_3 must establish a connection to PLC_1. Doing
so, makes sure that routing from the PLC’s PN/IE interface to a CP module is possible as
well as routing from a CP module to the PLC’s PN/IE interface.
11.2.16.2
S7 routing between two CP interfaces
Since the S7-1200 CPUs support up to three CP modules, you can connect all three
modules to different S7 subnets. When you install at least two CP modules in the local base
of the CPU and connect to different S7 subnets, you can utilize routing.
In the example system below, in order for PLC_1 to communicate with PLC_3, the
Engineering System (ES) must rout messages by PLC_2 from the CP module to the CP
module in its local base. The ES must download the routing table for PLC_2, and PLC_2
must provide the routing table for the two CP modules. With these routing tables in place,
PLC_1 and PLC_3 can communicate with each other, even though not directly connected.
Also, you should note that routing takes place from CP module to CP module without
messages being sent over the PN/IE interface of PLC_2.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
963
Communication
11.2 PROFINET
11.2.17
Disabling SNMP
Simple Network Management Protocol (SNMP) is an Internet-standard protocol for collecting
and organizing information about managed devices on IP networks and for modifying that
information to change device behavior. Devices that typically support SNMP include routers,
switches, servers, workstations, printers, modem racks, and more.
SNMP is widely used in network management systems to monitor network-attached devices
for conditions that warrant administrative attention. SNMP uses various services and tools
for detection and diagnostics of the network topology. Information about the properties of
devices capable of SNMP is contained in Management Information Base (MIB) files for
which the user needs to have the appropriate rights. SNMP exposes management data in
the form of variables on the managed systems, which describe the system configuration.
These variables can then be queried (and sometimes set) by managing applications.
SNMP uses the UDP transport protocol and has two network components:
● SNMP manager: Monitors the network nodes
● SNMP client: Collects the various network-specific information in the individual network
nodes and stores it in a structured form in the Management Information Base (MIB). With
this data, detailed network diagnostics can be performed.
Under certain conditions, your application may require you to disable SNMP. Examples of
these conditions include the following:
● The security settings in your network do not allow the use of SNMP.
● You use your own SNMP solution (for example, with your own communications
instructions).
If you disable SNMP for a device, you no longer have some options for diagnostics of the
network topology (for example, using the PRONETA tool or the web server of the CPU).
S7-1200 Programmable controller
964
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.17.1
Disabling SNMP
Disabling SNMP
Follow these steps to disable SNMP in the S7-1200 CPU:
1. Create a classic data block (DB):
2. Select the Properties of the newly-created DB.
3. Select the Attributes tab. Deselect the check box for "Optimized block access":
4. Click the OK button.
A message displays advising you to recompile your program. Recompile your program at
this time.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
965
Communication
11.2 PROFINET
5. In the classic DB block interface, create the following static tags with the values shown.
You will use these tags in your program to disable the internal SNMP implementation:
6. In the Startup OB (OB100), add the Temporary variables as shown:
7. Using the LAD editor, in the Startup OB (OB100), in Network 1, insert a Label (Jump
label) (in the example below, the Label is named "Check") and a WRREC (Write Record)
instruction with the inputs and outputs shown:
8. Insert the following loop and check code with the Jump to Label (JMP) output. This code
ensures that the call completes and that you disable SNMP before leaving the Startup
OB:
S7-1200 Programmable controller
966
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.2 PROFINET
11.2.18
Diagnostics
Refer to "Organization blocks (OBs)" (Page 92) for information on how to use organization
blocks (OBs) for diagnostics with these communication networks.
11.2.19
Distributed I/O instructions
Refer to "Distributed I/O (PROFINET, PROFIBUS, or AS-i)" (Page 384) for information on
how to use the distributed I/O instructions with these communication networks.
11.2.20
Diagnostic instructions
Refer to the "Diagnostics (PROFINET or PROFIBUS)": "Diagnostics instructions" (Page 439)
for information on how to use these instructions with these communication networks.
11.2.21
Diagnostic events for distributed I/O
Refer to the "Diagnostics (PROFINET or PROFIBUS)": "Diagnostics events for distributed
I/O" (Page 486) for information on how to use this diagnostic information with these
communication networks.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
967
Communication
11.3 PROFIBUS
11.3
PROFIBUS
A PROFIBUS system uses a bus master to poll slave devices distributed in a multi-drop
fashion on an RS485 serial bus. A PROFIBUS slave is any peripheral device (I/O
transducer, valve, motor drive, or other measuring device) which processes information and
sends its output to the master. The slave forms a passive station on the network since it
does not have bus access rights, and can only acknowledge received messages, or send
response messages to the master upon request. All PROFIBUS slaves have the same
priority, and all network communication originates from the master.
A PROFIBUS master forms an "active station" on the network. PROFIBUS DP defines two
classes of masters. A class 1 master (normally a central programmable controller (PLC) or a
PC running special software) handles the normal communication or exchange of data with
the slaves assigned to it. A class 2 master (usually a configuration device, such as a laptop
or programming console used for commissioning, maintenance, or diagnostics purposes) is
a special device primarily used for commissioning slaves and for diagnostic purposes.
The S7-1200 is connected to a PROFIBUS network as a DP slave with the CM 1242-5
communication module. The CM 1242-5 (DP slave) module can be the communications
partner of DP V0/V1 masters. If you want to configure the module in a third-party system,
there is a GSD file available for the CM 1242-5 (DP slave) on the CD that ships with the
module and on Siemens Automation Customer Support
(https://support.industry.siemens.com/cs/ww/en/ps/6GK7242-5DX30-0XE0) pages on the
Internet.
In the figure below, the S7-1200 is a DP slave to an S7-300 controller:
The S7-1200 is connected to a PROFIBUS network as a DP master with the CM 1243-5
communication module. The CM 1243-5 (DP master) module can be the communications
partner of DP V0/V1 slaves. In the figure below, the S7-1200 is a master controlling an
ET 200SP DP slave:
S7-1200 Programmable controller
968
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.3 PROFIBUS
If a CM 1242-5 and a CM 1243-5 are installed together, an S7-1200 can perform as both a
slave of a higher-level DP master system and a master of a lower-level DP slave system,
simultaneously:
As of V3.0, you can configure a maximum of three PROFIBUS CMs per station, in which
there can be any combination of DP master or DP slave CMs. DP masters in a V3.0 or
greater CPU firmware implementation can each control a maximum of 32 slaves.
The configuration data of the PROFIBUS CMs is stored on the local CPU. This allows simple
replacement of these communications modules when necessary.
To use PROFIBUS with S7-1200 V4.0 or later CPUs, you must upgrade the PROFIBUS
Master CM firmware to at least V1.3.
Note
Always update the PROFIBUS CM firmware to the latest version available
(http://support.automation.siemens.com/WW/view/en/42131407). You can perform a
firmware update by any of these methods:
• Using the online and diagnostic tools of STEP 7 (Page 1318)
• Using a SIMATIC memory card (Page 148)
• Using the Web server "Module Information" standard Web page (Page 1023)
• Using the SIMATIC Automation Tool
(https://support.industry.siemens.com/cs/ww/en/view/98161300)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
969
Communication
11.3 PROFIBUS
11.3.1
Communications services of the PROFIBUS CMs
The PROFIBUS CMs use the PROFIBUS DP-V1 protocol.
Types of communication with DP-V1
The following types of communication are available with DP-V1:
● Cyclic communication (CM 1242-5 and CM 1243-5)
Both PROFIBUS modules support cyclic communication for the transfer of process data
between DP slave and DP master.
Cyclic communication is handled by the operating system of the CPU. No software blocks
are required for this. The I/O data is read or written directly from/to the process image of
the CPU.
● Acyclic communication (CM 1243-5 only)
The DP master module also supports acyclic communication using software blocks:
– The "RALRM" instruction is available for interrupt handling.
– The "RDREC" and "WRREC" instructions are available for transferring configuration
and diagnostics data.
Functions not supported by the CM 1243-5: SYNC/FREEZE and Get_Master_Diag
Other communications services of the CM 1243-5
The CM 1243-5 DP master module supports the following additional communications
services:
● S7 communication
– PUT/GET services
The DP master functions as a client and server for queries from other S7 controllers or
PCs via PROFIBUS.
– PG/OP communication
The PG functions allow the downloading of configuration data and user programs from
a PG and the transfer of diagnostics data to a PG.
Possible communications partners for OP communication are HMI panels, SIMATIC
panel PCs with WinCC flexible or SCADA systems that support S7 communication.
S7-1200 Programmable controller
970
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.3 PROFIBUS
11.3.2
Reference to the PROFIBUS CM user manuals
Further information
You can find detailed information on the PROFIBUS CMs in the manuals for the devices.
You can find these on the Internet in the pages of Siemens Industrial Automation Customer
Support under the following entry IDs:
● CM 1242-5 (https://support.industry.siemens.com/cs/ww/en/ps/15667)
● CM 1243-5 (https://support.industry.siemens.com/cs/ww/en/ps/15669)
11.3.3
Configuring a DP master and slave device
11.3.3.1
Adding the CM 1243-5 (DP master) module and a DP slave
In the "Devices and networks" portal, use the hardware catalog to add PROFIBUS modules
to the CPU. These modules are connected to the left side of the CPU. To insert a module
into the hardware configuration, select the module in the hardware catalog and either
double-click or drag the module to the highlighted slot.
Table 11- 54 Adding a PROFIBUS CM 1243-5 (DP master) module to the device configuration
Module
Select the module
Insert the module
Result
CM 1243-5
(DP master)
Use the hardware catalog to add DP slaves as well. For example, to add an ET 200SP DP
slave, in the Hardware Catalog, expand the following containers:
● Distributed I/O
● ET 200SP
● Interface modules
● PROFIBUS
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
971
Communication
11.3 PROFIBUS
Next, select "6ES7 155-6BU00-0CN0" (IM155-6 DP HF) from the list of part numbers, and
add the ET 200SP DP slave as shown in the figure below.
Table 11- 55 Adding an ET 200SP DP slave to the device configuration
Insert the DP slave
11.3.3.2
Result
Configuring logical network connections between two PROFIBUS devices
After you configure the CM 1243-5 (DP master) module, you are now ready to configure your
network connections.
In the Devices and Networks portal, use the "Network view" to create the network
connections between the devices in your project. To create the PROFIBUS connection,
select the purple (PROFIBUS) box on the first device. Drag a line to the PROFIBUS box on
the second device. Release the mouse button and your PROFIBUS connection is joined.
Refer to "Device Configuration: Creating a network connection" (Page 806) for more
information.
11.3.3.3
Assigning PROFIBUS addresses to the CM 1243-5 module and DP slave
Configuring the PROFIBUS interface
After you configure logical network connections between two PROFIBUS devices, you can
configure parameters for the PROFIBUS interfaces. To do so, click the purple PROFIBUS
box on the CM 1243-5 module, and the "Properties" tab in the inspector window displays the
PROFIBUS interface. The DP slave PROFIBUS interface is configured in the same manner.
Table 11- 56 Configuring the CM 1243-5 (DP master) module and ET 200SP DP slave PROFIBUS interfaces
CM 1243-5 (DP master) module
ET 200SP DP slave
① PROFIBUS port
S7-1200 Programmable controller
972
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.3 PROFIBUS
Assigning the PROFIBUS address
In a PROFIBUS network, each device is assigned a PROFIBUS address. This address can
range from 0 through 127, with the following exceptions:
● Address 0: Reserved for network configuration and/or programming tools attached to the
bus
● Address 1: Reserved by Siemens for the first master
● Address 126: Reserved for devices from the factory that do not have a switch setting and
must be re-addressed through the network
● Address 127: Reserved for broadcast messages to all devices on the network and may
not be assigned to operational devices
Thus, the addresses that may be used for PROFIBUS operational devices are 2 through
125.
In the Properties window, select the "PROFIBUS address" configuration entry. STEP 7
displays the PROFIBUS address configuration dialog, which is used to assign the
PROFIBUS address of the device.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
973
Communication
11.3 PROFIBUS
Table 11- 57 Parameters for the PROFIBUS address
Parameter
Subnet
Parameters
Description
Name of the Subnet to which the device is connected. Click the "Add new subnet" button to create a
new subnet. "Not connected" is the default. Two connection types are possible:
•
The "Not connected" default provides a local connection.
•
A subnet is required when your network has two or more devices.
Address
Assigned PROFIBUS address for the device
Highest address
The highest PROFIBUS address is based on the active stations on the
PROFIBUS (for example, DP master). Passive DP slaves independently
have PROFIBUS addresses from 1 to 125 even if the highest PROFIBUS
address is set to 15, for example. The highest PROFIBUS address is relevant for token forwarding (forwarding of the send rights), and the token is
only forwarded to active stations. Specifying the highest PROFIBUS address optimizes the bus.
Transmission rate
Transmission rate of the configured PROFIBUS network: The PROFIBUS
transmission rates range from 9.6 Kbits/sec to 12 Mbits/sec. The transmission rate setting depends on the properties of the PROFIBUS nodes being
used. The transmission rate should not be greater than the rate supported
by the slowest node.
The transmission rate is normally set for the master on the PROFIBUS
network, with all DP slaves automatically using that same transmission rate
(auto-baud).
11.3.4
Distributed I/O instructions
Refer to "Distributed I/O (PROFINET, PROFIBUS, or AS-i)" (Page 384) for information on
how to use the distributed I/O instructions with these communication networks.
11.3.5
Diagnostic instructions
Refer to the "Diagnostics (PROFINET or PROFIBUS)": "Diagnostics instructions" (Page 439)
for information on how to use these instructions with these communication networks.
11.3.6
Diagnostic events for distributed
Refer to the "Diagnostics (PROFINET or PROFIBUS)": "Diagnostics events for distributed
I/O" (Page 486) for information on how to use this diagnostic information with these
communication networks.
S7-1200 Programmable controller
974
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
11.4
AS-i
The S7-1200 AS-i master CM 1243-2 allows the attachment of an AS-i network to an S71200 CPU.
The actuator/sensor interface, or AS-i, is a single master network connection system for the
lowest level in automation systems. The CM 1243-2 serves as the AS-i master for the
network. Using a single AS-i cable, sensors and actuators (AS-i slave devices) can be
connected to the CPU through the CM 1243-2. The CM 1243-2 handles all AS-i network
coordination and relays data and status information from the actuators and sensors to the
CPU through the I/O addresses assigned to the CM 1243-2. You can access binary or
analog values depending on the slave type. The AS-i slaves are the input and output
channels of the AS-i system and are only active when called by the CM 1243-2.
In the figure below, the S7-1200 is an AS-i master controlling AS-i I/O module digital/analog
slave devices.
To use AS-i with S7-1200 V4.0 CPUs, you must upgrade the AS-i Master CM firmware to
V1.1.
You can make this upgrade using the webserver or a SIMATIC memory card.
Note
For V4.0 S7-1200 CPUs, if using the web server or a SIMATIC memory card to upgrade
from V1.0 to V1.1 AS-i firmware, you must update the AS-i firmware in the AS-i Master CM
1243-2 according to the following procedure:
1. Download the firmware upgrade to the AS-i Master CM 1243-2.
2. When the download is complete, power cycle the S7-1200 CPU to complete the firmware
upgrade process in the AS-i Master CM 1243-2.
3. Repeat steps 1 and 2 for each additional AS-i Master CM 1243-2. The S7-1200 PLC
allows a maximum of three AS-i Master CM 1243-2.
Note
It is recommended that you always update the AS-i CM firmware to the latest version
available (http://support.automation.siemens.com/WW/view/en/43416171)at the Siemens
Service and Support web site.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
975
Communication
11.4 AS-i
11.4.1
Configuring an AS-i master and slave device
The AS-i master CM 1243-2 is integrated into the S7-1200 automation system as a
communication module.
You can find detailed information on the AS-i master CM 1243-2 in the "AS-i master CM
1243-2 and AS-i data decoupling unit DCM 1271 for SIMATIC S7-1200" Manual
(https://support.industry.siemens.com/cs/ww/en/ps/15750/man).
11.4.1.1
Adding the AS-i master CM 1243-2 and AS-i slave
Use the hardware catalog to add AS-i master CM1243-2 modules to the CPU. These
modules are connected to the left side of the CPU, and a maximum of three AS-i master
CM1243-2 modules can be used. To insert a module into the hardware configuration, select
the module in the hardware catalog and either double-click or drag the module to the
highlighted slot.
Table 11- 58 Adding an AS-i master CM1243-2 module to the device configuration
Module
Select the module
Insert the module
Result
CM 1243-2
AS-i Master
Use the hardware catalog to add AS-i slaves as well. For example, to add an "I/O module,
compact, digital, input" slave, in the Hardware Catalog, expand the following containers:
● Field devices
● AS-Interface slaves
Next, select "3RG9 001-0AA00" (AS-i SM-U, 4DI) from the list of part numbers, and add the
"I/O module, compact, digital, input" slave as shown in the figure below.
Table 11- 59 Adding an AS-i slave to the device configuration
Insert the AS-i slave
Result
S7-1200 Programmable controller
976
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
11.4.1.2
Configuring logical network connections between two AS-i devices
After you configure the AS-i master CM1243-2, you are now ready to configure your network
connections.
In the Devices and Networks portal, use the "Network view" to create the network
connections between the devices in your project. To create the AS-i connection, select the
yellow (AS-i) box on the first device. Drag a line to the AS-i box on the second device.
Release the mouse button and your AS-i connection is joined.
Refer to "Device Configuration: Creating a network connection" (Page 806) for more
information.
11.4.1.3
Configuring the properties of the AS-i master CM1243-2
To configure parameters for the AS-i interface, click the yellow AS-i box on the AS-i master
CM1243-2 module, and the "Properties" tab in the inspector window displays the AS-i
interface.
In the STEP 7 inspector window, you can view, configure, and change general information,
addresses and operating parameters:
Table 11- 60 AS-i master CM1243-2 module properties
Property
Description
General
Name of the AS-i master CM 1243-2
Operating parameters
Parameters for the response of the AS-i master
I/O addresses
Address area for the slave I/O addresses
AS-i interface (X1)
Assigned AS-i network
Note
"Diagnostic interrupt for faults in the AS-i configuration" and "Automatic address
programming" are always active and are therefore shown in gray.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
977
Communication
11.4 AS-i
11.4.1.4
Assigning an AS-i address to an AS-i slave
Configuring the AS-i slave interface
To configure parameters for the AS-i interface, click the yellow AS-i box on the AS-i slave,
and the "Properties" tab in the inspector window displays the AS-i interface.
①
AS-i port
S7-1200 Programmable controller
978
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
Assigning the AS-i slave address
In an AS-i network, each device is assigned an AS-i slave address. This address can range
from 0 through 31; however, address 0 is reserved only for new slave devices. The slave
addresses are 1(A or B) to 31(A or B) for a total of up to 62 slave devices.
"Standard" AS-i devices use the entire address, having a number address without the A or B
designation. "A/B node" AS-i devices use the A or B portion of each address, enabling each
of the 31 addresses to be used twice. The address space range is 1A to 31A plus 1B to 31B.
Any address in the range of 1 - 31 can be assigned to an AS-i slave device; in other words, it
does not matter whether the slaves begin with address 21 or whether the first slave is
actually given the address 1.
In the example below, three AS-i devices have been addressed as "1" (a standard type
device), "2A" (an A/B node type device), and "3" (a standard type device):
①
②
③
AS-i slave address 1; Device: AS-i SM-U, 4DI; article number: 3RG9 001-0AA00
AS-i slave address 2A; Device: AS-i 8WD44, 3DO, A/B; article number: 8WD4 428-0BD
AS-i slave address 3; Device: AS-i SM-U, 2DI/2DO; article number: 3RG9 001-0AC00
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
979
Communication
11.4 AS-i
Enter the AS-i slave address here:
Table 11- 61 Parameters for the AS-i interface
Parameter
Description
Network
Name of the network to which the device is connected
Address(es)
Assigned AS-i address for the slave device in range of 1(A or B) to 31(A or B) for a total of up to 62
slave devices
S7-1200 Programmable controller
980
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
11.4.2
Exchanging data between the user program and AS-i slaves
11.4.2.1
STEP 7 basic configuration
The AS-i master reserves a 62-byte data area in the I/O area of the CPU. Access to the
digital data is performed here in bytes; for each slave, there is one byte of input and one byte
of output data.
The assignment of the AS-i connections of the AS-i digital slaves to the data bits of the
assigned byte is indicated in the inspection window of the AS-i master CM 1243-2.
You can access the data of the AS-i slaves in the user program by using the displayed I/O
addresses with the appropriate bit logic operations (for example, "AND") or bit assignments.
Note
"System assignment" is automatically activated if you do not configure the AS-i slaves with
STEP 7.
If you do not configure any slaves, you must inform the AS-i master CM1243-2 about the
actual bus configuration using the online function "ACTUAL > EXPECTED".
Further information
You can find detailed information on the AS-i master CM 1243-2 in the "AS-i master CM
1243-2 and AS-i data decoupling unit DCM 1271 for SIMATIC S7-1200" Manual
(https://support.industry.siemens.com/cs/ww/en/ps/15750/man).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
981
Communication
11.4 AS-i
11.4.2.2
Configuring slaves with STEP 7
Transferring AS-i digital values
The CPU accesses the digital inputs and outputs of the AS-i slaves through the AS-i master
CM1243-2 in cyclic operation. The data is accessed through I/O addresses or by means of a
data record transfer.
①
②
③
AS-i slave address 1
AS-i slave address 2A
AS-i slave address 3
Access to the digital data is performed here in bytes (in other words, one byte is assigned to
each AS-i digital slave). When you configure the AS-i slaves in STEP 7, the I/O address for
accessing the data from the user program is displayed in the inspection window for the
respective AS-i slave.
The digital input module (AS-i SM-U, 4DI) in the AS-i network above has been assigned
slave address 1. By clicking on the digital input module, the "AS interface" tab in the device
"Properties" displays the slave address, as shown below:
S7-1200 Programmable controller
982
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
The digital input module (AS-i SM-U, 4DI) in the AS-i network above has been assigned I/O
address 2. By clicking on the digital input module, the "I/O addresses" tab in the device
"Properties" displays the I/O address, as shown below:
You can access the data of the AS-i slaves in the user program by using their I/O addresses
with the appropriate bit logic operations (for example, "AND") or bit assignments. The
following simple program illustrates how the assignment works:
Input 2.0 is polled in this program. In the AS-i system, this input belongs to slave1 (Input byte
2, bit 0). Output 4.3, which is then set, corresponds to AS-i slave 3 (Output byte 4, bit 3)
Transferring AS-i analog values
You can access analog data of an AS-i slave through the process image of the CPU if you
have configured this AS-i slave in STEP 7 as an analog slave.
If you did not configure the analog slave in STEP 7, you can only access the data of the AS-i
slave through the acyclic functions (data record interface). In the user program of the CPU,
AS-i calls are read and written using the RDREC (read data record) and WRREC (write data
record) distributed I/O instructions.
Note
A configuration of the AS-i slaves specified through STEP 7 and downloaded into the S7
station is transferred by the CPU on the AS-i master CM1243-2 during S7 station start-up.
Any existing configuration that was determined through the "System assignment" online
function (Page 981) ("ACTUAL -> EXPECTED") will be overwritten.
Further information
You can find detailed information on the AS-i master CM 1243-2 in the "AS-i master CM
1243-2 and AS-i data decoupling unit DCM 1271 for SIMATIC S7-1200" Manual
(http://support.automation.siemens.com/WW/view/en/50414115/133300).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
983
Communication
11.4 AS-i
11.4.3
Distributed I/O instructions
Refer to "Distributed I/O (PROFINET, PROFIBUS, or AS-i)" (Page 384) for information on
how to use the distributed I/O instructions with these communication networks.
11.4.4
Working with AS-i online tools
Changing AS-i operational modes online
You must go online to view and change the AS-i operational modes.
In order to go online, your must first be in "Device configuration" with the AS-i master
CM1243-2 module selected, and then click the "Go online" button in the toolbar. Next, select
the "Online and diagnostics" command from the "Online" menu.
S7-1200 Programmable controller
984
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.4 AS-i
There are two AS-i operational modes:
● Protection mode:
– You cannot change AS-i slave device and CPU I/O addresses.
– The green "CM" LED is OFF.
● Configuration mode:
– You can make required changes in your AS-i slave device and CPU I/O addresses.
– The green "CM" LED is ON.
In the "Set AS-i address" field, you can change the AS-i slave address. A new slave that has
not been assigned an address always has address 0. It is detected by the master as a new
slave without an address assignment and is not included in normal communication until
assigned an address.
Configuration error
When the yellow "CER" LED is ON, there is an error in the AS-i slave device configuration.
Select the "ACTUAL > EXPECTED" button to overwrite the AS-i master CM1243-2 module
slave device configuration with the AS-i field network slave device configuration.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
985
Communication
11.5 S7 communication
11.5
S7 communication
11.5.1
GET and PUT (Read and write from a remote CPU)
You can use the GET and PUT instructions to communicate with S7 CPUs through
PROFINET and PROFIBUS connections. This is only possible if the "Permit access with
PUT/GET communication" function is activated for the partner CPU in the "Protection"
property of the local CPU properties:
● Accessing data in a remote CPU: An S7-1200 CPU can only use absolute addresses in
the ADDR_x input field to address variables of remote CPUs (S7-200/300/400/1200).
● Accessing data in a standard DB: An S7-1200 CPU can only use absolute addresses in
the ADDR_x input field to address DB variables in a standard DB of a remote S7 CPU.
● Accessing data in an optimized DB: An S7-1200 CPU cannot access DB variables in an
optimized DB of a remote S7-1200 CPU.
● Accessing data in a local CPU: An S7-1200 CPU can use either absolute or symbolic
addresses as inputs to the RD_x or SD_x input fields of the GET or PUT instruction,
respectively.
Note
V4.0 CPU program GET/PUT operation is not automatically enabled
A V3.0 CPU program GET/PUT operation is automatically enabled in a V4.0 CPU.
However, a V4.0 CPU program GET/PUT operation in a V4.0 CPU is not automatically
enabled. You must go to the CPU "Device configuration", inspector window "Properties"tab,
"Protection" property to enable GET/PUT access (Page 210).
S7-1200 Programmable controller
986
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
Table 11- 62 GET and PUT instructions
LAD / FBD
SCL
"GET_DB"(
req:=_bool_in_,
ID:=_word_in_,
ndr=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
addr_1:=_remote_inout_,
[...addr_4:=_remote_inout_,]
rd_1:=_variant_inout_
[,...rd_4:=_variant_inout_]);
Description
"PUT_DB"(
req:=_bool_in_,
ID:=_word_in_,
done=>_bool_out_,
error=>_bool_out_,
status=>_word_out_,
addr_1:=_remote_inout_,
[...addr_4:=_remote_inout_,]
sd_1:=_variant_inout_,
[....sd_4:=_variant_inout_]);
Use the PUT instruction to write data to a
remote S7 CPU. The remote CPU can be
in either RUN or STOP mode.
Use the GET instruction to read data from
a remote S7 CPU. The remote CPU can
be in either RUN or STOP mode.
STEP 7 automatically creates the DB
when you insert the instruction.
STEP 7 automatically creates the DB
when you insert the instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
987
Communication
11.5 S7 communication
Table 11- 63 Data types for the parameters
Parameter and type
Data type
Description
REQ
Input
Bool
A low to high (positive edge) signal starts the operation.
ID
Input
CONN_PRG
(Word)
S7 connection ID (Hex)
NDR (GET)
Output
Bool
New Data Ready:
DONE (PUT)
Output
Bool
ERROR
Output
Bool
STATUS
Output
Word
•
0: request has not yet started or is still running
•
1: task was completed successfully
DONE:
•
0: request has not yet started or is still running
•
1: task was completed successfully
•
ERROR=0
STATUS value:
•
–
0000H: neither warning nor error
–
<> 0000H: Warning, STATUS supplies detailed information
ERROR=1
There is an error. STATUS supplies detailed information about
the nature of the error.
ADDR_1
InOut
Remote
Pointer to the memory areas in the remote CPU that stores the
data to be read (GET) or that is sent (PUT).
ADDR_2
InOut
Remote
ADDR_3
InOut
Remote
ADDR_4
InOut
Remote
RD_1 (GET)
SD_1 (PUT)
InOut
Variant
Pointer to the memory areas in the local CPU that stores the data
to be read (GET) or sent (PUT).
RD_2 (GET)
SD_2 (PUT)
InOut
Variant
Data types allowed: Bool (only a single bit allowed), Byte, Char,
Word, Int, DWord, DInt, or Real.
RD_3 (GET)
SD_3 (PUT)
InOut
Variant
Note: If the pointer accesses a DB, you must specify the absolute
address, such as:
RD_4 (GET)
SD_4 (PUT)
InOut
Variant
P# DB10.DBX5.0 Byte 10
In this case, 10 represents the number of bytes to GET or PUT.
S7-1200 Programmable controller
988
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
You must ensure that the length (number of bytes) and data types for the ADDR_x (remote
CPU) and RD_x or SD_x (local CPU) parameters match. The number after the identifier
"Byte" is the number of bytes referenced by the ADDR_x, RD_x, or SD_x parameter.
Note
The total number of bytes received on a GET instruction or the total number of bytes sent on
a PUT instruction is limited. The limitations are based on how many of the four possible
address and memory areas you use:
• If you use only ADDR_1 and RD_1/SD_1, a GET instruction can get 222 bytes and a PUT
instruction can send 212 bytes.
• If you use ADDR_1, RD_1/SD_1, ADDR_2, and RD_2/SD_2, a GET instruction can get a
total of 218 bytes and a PUT instruction can send a total of 196 bytes.
• If you use ADDR_1, RD_1/SD_1, ADDR_2, RD_2/SD_2, ADDR_3, and RD_3/SD_3 a
GET instruction can get a total of 214 bytes and a PUT instruction can send a total of 180
bytes.
• If you use ADDR_1, RD_1/SD_1, ADDR_2, RD_2/SD_2, ADDR_3, RD_3/SD_3, ADDR_4,
RD_4/SD_4 a GET instruction can get a total of 210 bytes and a PUT instruction can
send a total of 164 bytes.
The sum of the number of bytes of each of your address and memory area parameters must
be less than or equal to the defined limits. If you exceed these limits, the GET or PUT
instruction returns an error.
On the rising edge of the REQ parameter, the read operation (GET) or write operation (PUT)
loads the ID, ADDR_1, and RD_1 (GET) or SD_1 (PUT) parameters.
● For GET: The remote CPU returns the requested data to the receive areas (RD_x),
starting with the next scan. When the read operation has completed without error, the
NDR parameter is set to 1. A new operation can only be started after the previous
operation has completed.
● For PUT: The local CPU starts sending the data (SD_x) to the memory location (ADDR_x)
in the remote CPU. When the write operation has completed without error, the remote
CPU returns an execution acknowledgement. The DONE parameter of the PUT
instruction is then set to 1. A new write operation can only be started after the previous
operation has completed.
Note
To ensure data consistency, always evaluate when the operation has been completed
(NDR = 1 for GET, or DONE = 1 for PUT) before accessing the data or initiating another
read or write operation.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
989
Communication
11.5 S7 communication
The ERROR and STATUS parameters provide information about the status of the read
(GET) or write (PUT) operation.
Table 11- 64 Error information
ERROR
STATUS (decimal)
Description
0
11
•
New job cannot take effect since previous job is not yet completed.
•
The job is now being processed in a priority class having lower priority.
0
25
Communication has started. The job is being processed.
1
1
Communications problems, such as:
•
Connection description not loaded (local or remote)
•
Connection interrupted (for example: cable, CPU is turned off, or CM/CB/CP is in
STOP mode)
•
Connection to partner not yet established
1
2
Negative acknowledgement from the partner device. The task cannot be executed.
1
4
Errors in the send area pointers (RD_x for GET, or SD_x for PUT) involving the data
length or the data type.
1
8
Access error on the partner CPU
1
10
Access to the local user memory not possible (for example, attempting to access a
deleted DB)
1
12
When the SFB was called:
1
20
•
An instance DB was specified that does not belong to GET or PUT
•
No instance DB was specified, but rather a shared DB
•
No instance DB found (loading a new instance DB)
•
Exceeded the maximum number of parallel jobs/instances
• The instances were overloaded at CPU-RUN
This status is possible for first execution of the GET or PUT instruction
1
27
There is no corresponding GET or PUT instruction in the CPU.
S7-1200 Programmable controller
990
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
11.5.2
Creating an S7 connection
Connection mechanisms
To access remote connection partners with PUT/GET instructions, the user must also have
permission.
By default, the "Permit access with PUT/GET communication" option is not enabled. In this
case, read and write access to CPU data is only possible for communication connections
that require configuration or programming both for the local CPU and for the communication
partner. Access through BSEND/BRCV instructions is possible, for example.
Connections for which the local CPU is only a server (meaning that no
configuration/programming of the communication with the communication partner exists at
the local CPU), are therefore not possible during operation of the CPU, for example:
● PUT/GET, FETCH/WRITE or FTP access through communication modules
● PUT/GET access from other S7 CPUs
● HMI access through PUT/GET communication
If you want to allow access to CPU data from the client side, that is, you do not want to
restrict the communication services of the CPU, you can configure the access protection for
the S7-1200 CPU (Page 210) for this level of security.
Connection types
The connection type that you select creates a communication connection to a partner
station. The connection is set up, established, and automatically monitored.
In the Devices and Networks portal, use the "Network view" to create the network
connections between the devices in your project. First, click the "Connections" tab, and then
select the connection type with the dropdown, just to the right (for example, an S7
connection). Click the green (PROFINET) box on the first device, and drag a line to the
PROFINET box on the second device. Release the mouse button and your PROFINET
connection is joined.
Refer to "Creating a network connection" (Page 806) for more information.
Click the "Highlighted: Connection" button to access the "Properties" configuration dialog of
the communication instruction.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
991
Communication
11.5 S7 communication
11.5.3
Configuring the Local/Partner connection path between two devices
Configuring General parameters
You specify the communication parameters in the "Properties" configuration dialog of the
communication instruction. This dialog appears near the bottom of the page whenever you
have selected any part of the instruction.
Refer to "Device configuration: Configuring the Local/Partner connection path (Page 807)"
for more information.
In the "Address Details" section of the Connection parameters dialog, you define the TSAPs
or ports to be used. The TSAP or port of a connection in the CPU is entered in the "Local
TSAP" field. The TSAP or port assigned for the connection in your partner CPU is entered
under the "Partner TSAP" field.
11.5.4
GET/PUT connection parameter assignment
The GET/PUT instructions connection parameter assignment is a user aid for configuring
CPU-to-CPU S7 communication connections.
After inserting a GET or PUT block, STEP 7 displays the connection parameter assignment
dialog for the GET/PUT instructions:
S7-1200 Programmable controller
992
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
The inspector window displays the properties of the connection whenever you have selected
any part of the instruction. You can configure the communication parameters in the
"Configuration" tab of the "Properties" for the communication instruction.
Note
V4.1 and later CPU program GET/PUT operation is not automatically enabled
A V3.0 CPU program GET/PUT operation is automatically enabled in a V4.1 and later CPU.
However, a V4.1 and later CPU program GET/PUT operation in a V4.1 and later CPU is not
automatically enabled. You must go to the CPU "Device configuration", inspector window
"Properties"tab, "Protection" property to enable GET/PUT access (Page 210).
11.5.4.1
Connection parameters
The "Connection parameters" page allows you to configure the necessary S7 connection
and to configure the parameter "Connection ID" that is referenced by the GET/PUT block
parameter "ID". The page's content has information about the local endpoint and allows you
to define the local interface. You can also define the partner end point.
The "Block parameters" page allows you to configure the additional block parameters.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
993
Communication
11.5 S7 communication
Table 11- 65 Connection parameter: General definitions
Parameter
Connection
parameter:
General
Definition
End point
"Local End point": Name assigned to the Local CPU
"Partner End point": Name assigned to the Partner (remote) CPU
Note: In the "Partner End point" dropdown list, the system displays all potential
S7 connection partners of the current project as well as the option "unspecified". An unspecified partner represents a communication partner which is not
currently in the STEP 7 project (for example, a third party device communication partner).
Interface
Name assigned to the interfaces
Note: You can change the connection by changing the Local and Partner interfaces
Interface type
Type of interface
Subnet name
Name assigned to the subnets
Address
Assigned IP addresses
Note: You can specify the remote address of a third party device for an "unspecified" communication partner.
Connection ID
ID number: Automatically generated by the GET/PUT connection parameter
assignment
Connection name
Local and Partner CPU data storage location: Automatically generated by the
GET/PUT connection parameter assignment
Active connection establishment
Checkbox to select Local CPU as the active connection
One-way
Checkbox to specify a one-way or two-way connection; read-only
Note: In a PROFINET GET/PUT connection, both the local and partner devices can act as a server or a client. This allows a two-way connection, and the
"One-way" checkbox is unchecked.
In a PROFIBUS GET/PUT connection, in some cases, the Partner device can
only act as a server (for example, an S7-300), and the "One-way" checkbox is
checked.
Connection ID parameter
There are three ways to change the system-defined connection IDs:
1. The user can change the current ID directly on the GET/PUT block. If the new ID belongs
to an already existing connection, the connection is changed.
2. The user can change the current ID directly on the GET/PUT block, but the new ID does
not already exist. A new S7 connection is created by the system.
3. The user can change the current ID through the "Connection overview" dialog: The userinput is synchronized with the ID-parameter on the corresponding GET/PUT block.
Note
The parameter "ID" of the GET/PUT block is not a connection name, but a numerical
expression which is written like the following example: W#16#1
S7-1200 Programmable controller
994
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
Connection name parameter
The connection name is editable through a special user control, the "Connection overview"
dialog. This dialog offers all the available S7 connections which could be selected as an
alternative for the current GET/PUT communication. The user can create a completely new
connection in this table. Click the button to the right of the "Connection name" field to start
the "Connection overview" dialog.
11.5.4.2
Configuring a CPU-to-CPU S7 connection
Given the configuration of PLC_1, PLC_2, and PLC_3 as shown in the figure below, insert
GET or PUT blocks for "PLC_1".
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
995
Communication
11.5 S7 communication
For the GET or PUT instruction, the "Properties" tab is automatically displayed in the
inspector window with the following menu selections:
● "Configuration"
● "Connection parameters"
Configuring a PROFINET S7 connection
For the "Partner End point", select "PLC_3".
S7-1200 Programmable controller
996
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
The system reacts with the following changes:
Table 11- 66 Connection parameter: General values
Parameter
Connection
parameter:
General
Definition
End point
"Local End point" contains "PLC_1" as read-only.
"Partner End point" field contains "PLC_3[CPU319-3PN/DP]":
Interface
•
The color switches from red to white
•
The "Partner" device image is shown.
•
A connection line appears between the PLC_1- and PLC_3 device images
(green Ethernet line).
"Local Interface" contains "CPU1214C DC/DC/DC, PROFINET interface
(R0/S1)".
"Partner Interface" contains: "CPU319-3PN/DP, PROFINET interface
(R0/S2)".
Interface type
"Local Interface type" contains "Ethernet/IP"; control is read-only.
"Partner Interface type" contains "Ethernet/IP"; control is read-only.
Interface type images are shown at the right beside the Local and Partner
"Interface type" (green Ethernet icon).
Subnet name
"Local Subnet name" contains "PN/IE_1"; control is read only.
"Partner Subnet name" contains "PN/IE_1"; control is read only.
Address
"Local Address" contains the Local IP address; control is read only.
"Partner Address" contains the Partner IP address; control is read only.
Connection ID
"Connection ID" contains "100".
In the Program editor, in the Main [OB1], the GET/PUT block "Connection ID"
value also contains "100".
Connection name
"Connection name" contains the default connection name (for example,
"S7_Connection_1"); control is enabled.
Active connection establishment
Checked and enabled to select the Local CPU as the active connection.
One-way
Read-only and unchecked.
Note: "PLC_1" (an S7-1200 CPU 1214CDC/DC/Relay) and "PLC_3" (an S7300 CPU 319-3PN/DP) can both act as a server and a client in a PROFINET
GET/PUT connection, allowing a two-way connection.
The GET/PUT icon in the Property View tree also changes from red to green.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
997
Communication
11.5 S7 communication
Completed PROFINET S7 connection
In the "Network view", a two-way S7 connection is shown in the "Connections" table between
"PLC_1" and "PLC_3".
Configuring a PROFIBUS S7 connection
For the "Partner End point", select "PLC_3".
S7-1200 Programmable controller
998
System Manual, V4.2, 09/2016, A5E02486680-AK
Communication
11.5 S7 communication
The system reacts with the following changes:
Table 11- 67 Connection parameter: General values
Parameter
Connection
parameter:
General
Definition
End point
"Local End point" contains "PLC_1" as read-only.
"Partner End point" field contains "PLC_3[CPU319-3PN/DP]":
Interface
•
The color switches from red to white
•
The "Partner" device image is shown.
•
A connection line appears between the PLC_1- and PLC_3 device images
(purple PROFIBUS line).
"Local Interface" contains "CPU1214C DC/DC/DC, PROFIBUS interface
(R0/S1)".
"Partner Interface" contains: "CPU319-3PN/DP, PROFIBUS interface
(R0/S2)".
Interface type
"Local Interface type" contains "PROFIBUS"; control is read-only.
"Partner Interface type" contains " PROFIBUS "; control is read-only.
Interface type images are shown at the right beside the Local and Partner
"Interface type" (purple PROFIBUS icon).
Subnet name
"Local Subnet name" contains " PROFIBUS _1"; control is read only.
"Partner Subnet name" contains " PROFIBUS _1"; control is read only.
Address
"Local Address" contains the Local IP address; control is read only.
"Partner Address" contains the Partner IP address; control is read only.
Connection ID
"Connection ID" contains "100".
In the Program editor, in the Main [OB1], the GET/PUT block "Connection ID"
value also contains "100".
Connection name
"Connection name" contains the default connection name (for example,
"S7_Connection_1"); control is enabled.
Active connection establishment
Read-only, checked, and enabled to select the Local CPU as the active connection.
One-way
Read-only and checked.
Note: "PLC_3" (an S7-300 CPU319-3PN/DP) can act only as a server (cannot
also be a client) in a PROFIBUS GET/PUT connection, allowing only a oneway connection.
The GET/PUT icon in the Property View tree also changes from red to green.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
999
Communication
11.5 S7 communication
Completed PROFIBUS S7 connection
In the "Network view", a one-way S7 connection is shown in the "Connections" table
between "PLC_1" and "PLC_3".
S7-1200 Programmable controller
1000
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12
The Web server for the S7-1200 provides Web page access to data about your CPU and
process data.
You can access the S7-1200 Web pages from
a PC or from a mobile device. For devices
with small screens, the Web server supports a
collection of basic pages (Page 1012).
You use a Web browser to access the IP address of the S7-1200 CPU or the IP address
of a Web server-enabled CP (communications
processor) module (Page 1010) in the local
rack with the CPU to establish the connection.
The S7-1200 supports multiple concurrent
connections.
Standard Web pages
The S7-1200 includes standard Web pages (Page 1011) that you can access from the Web
browser of your PC (Page 1007) or from a mobile device (Page 1009):
● Introduction (Page 1017) - entry point to the standard Web pages
● Start Page (Page 1018) - general information about the CPU
● Diagnostics (Page 1019) - detailed information about the CPU including serial, order, and
version numbers, program protection, and memory usage
● Module Information (Page 1023) - information about the local and remote modules and
the ability to update firmware for local modules
● Communication (Page 1027) - information about the network addresses, physical
properties of the communication interfaces, statistics, parameters, as well as a
connection summary and diagnostic information
● Diagnostic Buffer (Page 1022) - the diagnostic buffer
● Tag status (Page 1031) - CPU variables and I/O, accessible by address or PLC tag name
● Watch tables (Page 1033) - watch tables that you configured in STEP 7
● Online backup (Page 1035) - ability to backup an online CPU or restore a previouslymade online backup
● File Browser (Page 1037) - browser for files stored internally in the CPU or on a memory
card, for example, data logs and recipes
● Login (Page 1013) - log in as a different user, or log out.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1001
Web server
These pages are built in to the S7-1200 CPU, and are available in English, German, French,
Spanish, Italian, and Simplified Chinese. All pages except for the Introduction and Start page
require additional user privileges (Page 1005) that you configure in STEP 7 to view the page.
User-defined Web pages
The S7-1200 also provides support for you to create user-defined Web pages that can
access CPU data. You can develop these pages with the HTML authoring software of your
choice, and include pre-defined "AWP" (Automation Web Programming) commands in your
HTML code to access CPU data. Refer to the User-defined Web pages (Page 1040) chapter
for specific information on the development of user-defined Web pages, and the associated
configuration and programming in STEP 7.
You can access the user-defined pages from either a PC or mobile device from the standard
or basic Web pages. You can also configure one of your user-defined Web pages to be the
entry page (Page 1058) for the Web server.
Web browser requirement
The Web server supports the following Web browsers for the standard pages:
● Internet Explorer 8 to 11
● Microsoft Edge
● Mozilla Firefox V22 to V32, V42 to V47
● Google Chrome V33 to V38, V46 to V47
● Mobile Safari and Mobile Chrome for iOS 9 devices
● Android browser for the following versions:
– Jellybean v4.3
– Kitkat v4.4
– Lollipop V5.0 to v5.1
– Marshmellow v6.0
● Mobile Chrome for Google Android
When using the HTML Browser control in a WinCC project, the Web server supports the
following Siemens HMI Panels for the standard pages:
● Basic Panels
– Gen 2 KTP400 to KTP1200
● Comfort Panels
– TP700 to TP2200
– KP400 to KP1500
– KTP400
– TP700 Comfort Outdoor
S7-1200 Programmable controller
1002
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.1 Enabling the Web server
● Mobile Panels
– Gen 2 KTP700[F], KTP900[F]
For browser-related restrictions that can interfere with the display of standard or user-defined
Web pages, see the Constraints (Page 1082) section.
12.1
Enabling the Web server
You enable the Web server in STEP 7 from Device Configuration for the CPU to which you
intend to connect.
To enable the Web server, follow these steps:
1. Select the CPU in the Device Configuration view.
2. In the inspector window, select "Web server" from the CPU properties.
3. Select the check box for "Activate web server on all modules of this device".
4. For increased security, ensure that "Permit access only with HTTPS" is selected to
require secure access to the Web server.
5. If you select "Enable automatic update" for "Automatic update", standard Web pages will
refresh by default every ten seconds. You you can also enter a custom refresh time
period in seconds for the "Update interval" field.
WARNING
Unauthorized access to the CPU through the Web server
Unauthorized access to the CPU or changing PLC variables to invalid values could disrupt
process operation and could result in death, severe personal injury and/or property
damage.
Because enabling the Web server allows authorized users to perform operating mode
changes, writes to PLC data, and firmware updates, Siemens recommends that you
observe the following security practices:
• Enable access to the Web server only with the HTTPS protocol.
• Password-protect Web server user IDs (Page 1005) with a strong password. Strong
passwords are at least ten characters in length, mix letters, numbers, and special
characters, are not words that can be found in a dictionary, and are not names or
identifiers that can be derived from personal information. Keep the password secret and
change it frequently.
• Do not extend the default minimum privileges of the "Everybody" user.
• Perform error-checking and range-checking on your variables in your program logic
because Web page users can change PLC variables to invalid values.
• Use a secure Virtual Private Network (VPN) to connect to the S7-1200 PLC Web server
from a location outside your protected network.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1003
Web server
12.1 Enabling the Web server
After you download the device configuration, you can use the standard Web pages to access
the CPU.
If you created and enabled user-defined Web pages (Page 1040), you can access them from
the standard or basic Web page navigation menu.
Note
Device exchange: Replacing a V3.0 CPU with a V4.x CPU
If you replace an existing V3.0 CPU with a V4.x CPU (Page 1571) and convert your V3.0
project to a V4.x project, note that STEP 7 and the V4.x CPU retain the Web server settings
for
• "Activate web server on all modules of this device"
• "Permit access only with HTTPS"
Note
If a "Download in RUN" (Page 1335) is in progress, standard and user-defined Web pages
do not update data values or permit you to write data values until the download is complete.
The Web server discards any attempts to write data values while a download is in progress.
S7-1200 Programmable controller
1004
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.2 Configuring Web server users
12.2
Configuring Web server users
You can configure users with various privilege levels for accessing the CPU through the Web
server.
To configure Web server users and their associated privileges, follow these steps:
1. Select the CPU in the Device Configuration view.
2. In the inspector window, select "Web server" from the CPU properties and enable the
Web server (Page 1003).
3. Select "User management" in the Web server properties.
4. Enter user names, access levels, and passwords for the user logins that you want to
provide.
After you download the configuration to the CPU, only authorized users can access Web
server functions for which they have privileges.
Web server access levels
STEP 7 provides a default user named "Everybody" with no password. By default, this user
has no additional privileges and can only view the Start (Page 1018) and Introduction
(Page 1017) standard Web pages. You can, however, configure additional privileges for the
"Everybody" user as well as other users:
● Query diagnostics
● Read tags
● Write tags
● Read tag status
● Write tag status
● Open user-defined web pages
● Write in user-defined web pages
● Read files
● Write/delete files
● Change operating mode
● Flash LEDs
● Perform a firmware update
● Backup CPU
● Restore CPU
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1005
Web server
12.2 Configuring Web server users
If you have set a user-defined Web page to be the entry page (Page 1058) for the Web
server, the Everybody user must have the "Open user-defined web pages" privilege.
WARNING
Access to Web server
Granting privileges to the "Everybody" user makes it possible to log in to the Web server
with no password. Unauthorized access to the CPU or changing PLC variables to invalid
values could disrupt process operation and could result in death, severe personal injury
and/or property damage.
Because the "Everybody" user when granted sufficient privileges can perform operating
mode changes, writes to PLC data, and firmware updates with no password, Siemens
recommends that you observe the following security practices
• Enable access to the Web server only with the HTTPS protocol.
• Password-protect Web server user IDs with a strong password. Strong passwords are at
least ten characters in length, mix letters, numbers, and special characters, are not
words that can be found in a dictionary, and are not names or identifiers that can be
derived from personal information. Keep the password secret and change it frequently.
• Do not extend the default minimum privileges of the "Everybody" user.
• Perform error-checking and range-checking on your variables in your program logic
because Web page users can change PLC variables to invalid values.
• Use a secure Virtual Private Network (VPN) to connect to the S7-1200 PLC Web server
from a location outside your protected network.
S7-1200 Programmable controller
1006
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.3 Accessing the Web pages from a PC
12.3
Accessing the Web pages from a PC
You can access the S7-1200 standard Web pages from a PC or from a mobile device
through the IP address of the S7-1200 CPU or the IP address of any Web server-enabled
CP (Page 1010) in the local rack.
To access the S7-1200 standard Web pages from a PC, follow these steps:
1. Ensure that the S7-1200 and the PC are on a common Ethernet network or are
connected directly to each other with a standard Ethernet cable.
2. Open a Web browser and enter the URL "https://ww.xx.yy.zz", where "ww.xx.yy.zz"
corresponds to the IP address of the S7-1200 CPU or the IP address of a CP in the local
rack.
The Web browser opens the Introduction standard Web page (Page 1017) or the Default
HTML page of your user-defined Web pages if you configured it to be the entry page
(Page 1058).
Note
Use a secure Virtual Private Network (VPN) to connect to the S7-1200 PLC Web server from
a location outside your protected network. Be aware also of any constraints (Page 1082) that
your Web environment or operating system might impose.
Alternatively, you can address your Web browser to a specific standard Web page. To do so,
enter the URL in the form "https://ww.xx.yy.zz/.html", where corresponds to
one of the standard Web pages:
● start (Page 1018) - general information about the CPU
● identification (Page 1019) - detailed information about the CPU including serial, order,
and version numbers, now called the Diagnostics page
● module (Page 1023) - information about the modules in the local rack and the ability to
update firmware
● communication (Page 1027) - information about the network addresses, physical
properties of the communication interfaces, and communication statistics
● diagnostic (Page 1022) - the diagnostic buffer
● variable (Page 1031) - CPU variables (tags) and I/O, accessible by address, PLC tag
name, or data block tag name
● watch (Page 1033) - watch tables
● filebrowser (Page 1037) - browser for accessing data log files or recipe files stored
internally in the CPU or on a memory card
● index (Page 1017) - introduction page to enter the standard Web pages
● login (Page 1013) - page to log in if no user is currently logged in; otherwise, the page is
blank.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1007
Web server
12.3 Accessing the Web pages from a PC
For example, if you enter "https://ww.xx.yy.zz/communication.html", the browser displays the
communication page.
Note
Note that any standard Web page that is not listed specifically above (for example, the
Online backup page (Page 1035)) does not have a direct access URL.
Secure access
Use a secure Virtual Private Network (VPN) to connect to the S7-1200 PLC Web server from
a location outside your protected network. Require and use https:// instead of http:// for
secure access (Page 1003) to the standard Web pages. When you connect to the S7-1200
with https://, the Web site encrypts the session with a digital certificate. The Web server
transmits the data securely and it is not accessible for anyone to view. You typically get a
security warning that you can confirm with "Yes" to proceed to the standard Web pages. To
avoid the security warning with each secure access, you can import the Siemens software
certificate to your Web browser (Page 1085).
S7-1200 Programmable controller
1008
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.4 Accessing the Web pages from a mobile device
12.4
Accessing the Web pages from a mobile device
To access an S7-1200 from a mobile device, you must connect your PLC to a network that
connects to the Internet or to a local wireless access point. Use a secure Virtual Private
Network (VPN) to connect a mobile device to the S7-1200 PLC Web server. You can use
port forwarding in the wireless router to map the IP address of the PLC to an address by
which a mobile device can access it from the Internet. To configure port forwarding, follow
the instructions for the software configuration of your router. You can connect as many PLCs
and switching devices as your router supports.
Without port forwarding, you can connect to a PLC, but only locally within range of the
wireless signal.
In this example, a mobile device that is within range of the local wireless access point can
connect to PLC 3 and PLC 4 by their IP addresses. From the Internet outside the local
wireless range, a mobile device can connect to PLC 1 and PLC 2 using the port forwarded
address for each PLC.
To access the standard Web pages, you must have access to a cellular service or wireless
access point. To access a PLC from the Internet, enter the port forwarded address in the
Web browser of your mobile device to access the PLC, for example http://ww.xx.yy.zz:pppp
or https:/ww.xx.yy.zz:pppp, where ww.xx.yy.zz is the address of the router and pppp is the
port assignment for a specific PLC.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1009
Web server
12.5 Using a CP module to access Web pages
For local access through a local wireless access point, enter the IP address of the S7-1200
CPU or a Web server-enabled CP (Page 1010) in the local rack:
● http://ww.xx.yy.zz or https::/ww.xx.yy.zz to access the standard Web pages (Page 1011)
● http://ww.xx.yy.zz/basic or https::/ww.xx.yy.zz/basic to access the basic Web pages
(Page 1012)
For increased security, configure the Web server to be accessible only by secure access
(HTTPS) (Page 1003).
12.5
Using a CP module to access Web pages
Regardless of whether you access the Web server from a PC or a mobile device, you can
connect to standard Web pages through one of the following CP modules when you have
configured it in STEP 7 and installed it in the local rack with the S7-1200 CPU:
● CP 1242-7 GPRS V2
● CP 1243-1
● CP 1243-1 PCC
● CP 1243-7 LTE-EU
● CP 1243-7 LTE-US
● CP 1243-8 IRC
You use the Start standard Web page (Page 1018) to access the Web pages through these
CP modules. The Start page displays all configured and installed CP modules that you have
in your local rack, but you can only access Web pages from the ones listed above.
Note
Access to standard Web pages when Web server-enabled CPs are in the local rack
You might observe delays up to one or two minutes when connecting to the S7-1200
standard Web pages when Web server-enabled CPs are in the local rack. If the pages do
not appear to be available, or you get errors, just wait one or two minutes and refresh the
page.
S7-1200 Programmable controller
1010
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6
Standard Web pages
12.6.1
Layout of the standard Web pages
Each of the S7-1200 standard Web pages has a common layout with navigational links and
page controls. Regardless of whether you are viewing the page on a PC or on a mobile
device, each page has the same content area, but the layout and navigation controls vary
based on the screen size and resolution of the device. On a standard PC or large mobile
device the layout of a standard Web page appears as follows:
①
②
③
④
⑤
⑥
⑦
Web server header with selector to display PLC Local time or UTC time, and a selector for the
display language (Page 170)
Log in or log out
Standard Web page header with name of the page that you are viewing. This example is the
CPU Identification page. Some of the standard Web pages, such as module information, also
display a navigation path here if multiple screens of that type can be accessed.
Refresh icon: for pages with automatic refresh, enables or disables the automatic refresh function; for pages without automatic refresh, causes the page to update with current data
Print icon: prepares and displays a printable version of the information available from the displayed page
Navigation area to switch to another page
Content area for specific standard Web page that you are viewing. This example is the Diagnostics page.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1011
Web server
12.6 Standard Web pages
Note
CP module standard Web pages
Certain CP modules (Page 1010) provide standard Web pages that are similar in
appearance and functionality to the S7-1200 CPU standard Web pages. Refer to your CP
documentation for descriptions of the CP standard Web pages.
12.6.2
Basic pages
The Web server provides basic pages intended for use on mobile devices. You access the
basic pages using the IP address of the device and appending "basic" to the URL:
http://ww.xx.yy.zz/basic or https::/ww.xx.yy.zz/basic
The basic pages look similar to the standard pages, but with some differences. The page
omits the navigation area, login area, and the header area, and includes buttons for
advancing backward and forward through the Web pages. Basic pages also include a Home
page button that takes you to a Navigation page. You can also use the navigation controls
provided with your mobile device for navigation. For example, the basic Diagnostics page
appears as follows in the vertical orientation:
The minimum resolution for displaying a basic page is 240 x 240 pixels.
Note that the standard Web page illustrations in this chapter represent the standard PC Web
page appearance. Most of the standard Web pages have equivalent basic pages.
S7-1200 Programmable controller
1012
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.3
Logging in and user privileges
Each of the PC standard Web pages provides a login window above the navigation pane.
Due to space considerations, the basic Web pages provide a separate Login page. The S71200 supports multiple user logins with various access levels (privileges):
● Query diagnostics
● Read tags
● Write tags
● Read tag status
● Write tag status
● Open user-defined pages
● Write in user-defined pages
● Read files
● Write/delete files
● Change operating mode
● Flash LEDs
● Perform firmware update
● Backup CPU
● Restore CPU
● Change system parameter
● Change application parameter
You configure user roles, associated access levels (privileges), and passwords (Page 1005)
in the Web server user management properties of the STEP 7 device configuration of the
CPU.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1013
Web server
12.6 Standard Web pages
Logging in
STEP 7 provides a default user named "Everybody" with no password. By default, this user
has no additional privileges and can only view the Start (Page 1018) and Introduction
(Page 1017) standard Web pages. You can, however, grant additional privileges to the
"Everybody" user as well as other users that you configure:
WARNING
Access to Web server
Granting privileges to the "Everybody" user makes it possible to log in to the Web server
with no password. Unauthorized access to the CPU or changing PLC variables to invalid
values could disrupt process operation and could result in death, severe personal injury
and/or property damage.
Because the "Everybody" user when granted sufficient privileges can perform operating
mode changes, writes to PLC data, and firmware updates with no password, Siemens
recommends that you observe the following security practices
• Enable access to the Web server only with the HTTPS protocol.
• Password-protect Web server user IDs (Page 1005) with a strong password. Strong
passwords are at least ten characters in length, mix letters, numbers, and special
characters, are not words that can be found in a dictionary, and are not names or
identifiers that can be derived from personal information. Keep the password secret and
change it frequently.
• Do not extend the default minimum privileges of the "Everybody" user.
• Perform error-checking and range-checking on your variables in your program logic
because Web page users can change PLC variables to invalid values.
• Use a secure Virtual Private Network (VPN) to connect to the S7-1200 PLC Web server
from a location outside your protected network.
S7-1200 Programmable controller
1014
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
To perform certain actions such as changing the operating mode of the controller, writing
values to memory, and updating the CPU firmware you must have the required privileges.
Note that if you have set the protection level of the CPU (Page 210) to "Complete protection
(no access)", then the "Everybody" user has no permission to access the Web server,
regardless of the Web server user permission settings.
The log in frame is near the upper left corner on
each standard Web page when displayed from a
PC or a wide mobile device.
The Log In page is a separate page on small mobile devices that display the basic pages. It is selectable from the Home page.
To log in, follow these steps:
1. Enter the user name for the Username field.
2. Enter the user password in the Password field.
Your login times out after thirty minutes of inactivity. If the currently-loaded page is
continually refreshing, the login does not time out.
Note
If you encounter any problems logging in, download the Siemens security certificate
(Page 1085) from the Introduction page (Page 1017). You can then log in with no errors.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1015
Web server
12.6 Standard Web pages
Logging out
To log out, simply click the "Logout" link from any page
when viewing from a PC or wide mobile device.
From the basic pages, navigate to the Login/Logout
page from the Home page and tap the "Logout" button.
After you log out, you can only access and view standard Web pages according to the
privileges of the "Everybody" user. Each of the standard Web page descriptions defines the
required privileges for that page.
Note
Log off prior to closing Web server
If you have logged in to the Web server, be sure to log off prior to closing your Web browser.
The Web server supports a maximum of seven concurrent logins.
S7-1200 Programmable controller
1016
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.4
Introduction
The Introduction page is the welcome screen for entry into the S7-1200 standard Web
pages.
From this page, you click "Enter" to access the S7-1200 standard Web pages. At the top of
the screen are links to useful Siemens Web sites, as well as a link to download the Siemens
security certificate (Page 1085). You can also choose to skip the introduction page on future
accesses to the Web server.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1017
Web server
12.6 Standard Web pages
12.6.5
Start
The Start page displays a representation of the CPU or CP to which you are connected and
lists general information about the device and the TIA Portal version you used to download
the project to the CPU. For the CPU, you can use the buttons to change the operating mode
and flash the LEDs, if you have logged in (Page 1013) with the "change operating mode"
privilege (Page 1005).
The bottom portion of the screen is visible if you have configured and installed Web serverenabled CP modules (Page 1010) in the local rack with the S7-1200 CPU. You can hover
over and click a Web server-enabled CP module to access the standard Web pages. Refer
to the documentation for your CP module for information about the CP module Web pages.
You see the name of the CP module when you hover over it.
The Web server also displays any other CM and CP modules in the local rack, but you
cannot click them as they do not contain Web pages. The module appearance for these CMs
and CPs are light gray (desensitized) to indicate that they are display-only and not clickable
modules.
Note that the S7-1200 fail-safe CPUs display additional data on this page related to
functional safety.
S7-1200 Programmable controller
1018
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.6
Diagnostics
The Diagnostics page displays identifying characteristics of the CPU, configuration settings
for know-how protection and memory usage for load memory, work memory, and retentive
memory:
The page consists of three tabs:
● Identification: identifying characteristics of the module and plant and location information
from STEP 7
● Program protection: status of know-how protection and CPU binding, which can be useful
in planning for spare parts as well as STEP 7 configuration setting for allowing or
preventing the copy of internal load memory to external load memory (SIMATIC memory
card).
● Memory: load, work, and retentive memory usage
For F-CPUs, there is an additional Fail-safe tab.
Viewing the Identification page requires the "query diagnostics" privilege (Page 1005).
Identification tab
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1019
Web server
12.6 Standard Web pages
Program protection tab
The program protection tab includes the following information:
● Know-how protection (Page 213): Displays whether you have configured know-how
protection for any of the program blocks in STEP 7
● Binding (Page 214): Displays whether you have bound the program to either the CPU or
to the SIMATIC memory card
● Program copy to memory card (Page 212): DIsplays whether you have enabled the ability
to copy the program from internal load memory to external load memory (SIMATIC
memory card)
S7-1200 Programmable controller
1020
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Memory tab
Fail-safe tab
Refer to the S7-1200 Functional Safety Manual
(https://support.industry.siemens.com/cs/ww/en/view/104547552) for information about the
Diagnostics page Fail-safe tab.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1021
Web server
12.6 Standard Web pages
12.6.7
Diagnostic Buffer
The diagnostic buffer page displays diagnostic events. From the selector on the left, you can
choose what range of diagnostic buffer entries to display, either 1 to 25 or 26 to 50. From the
selector on the right, you can choose whether to display the times in UTC times or PLC local
times. The top part of the page displays the diagnostic entries with the time and date of when
the event occurred.
From the top part of the page, you can select any individual entry to show detailed
information about that entry in the bottom part of the page. Note that the display language of
the diagnostic buffer entries depends upon your device configuration setting for multilingual
support (Page 175).
Viewing the Diagnostic Buffer page requires the "query diagnostics" privilege (Page 1005).
S7-1200 Programmable controller
1022
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.8
Module Information
The module information page provides information about all the modules in the local rack.
The top section of the screen shows a summary of the modules based on the device
configuration in STEP 7, and the bottom section shows status, identification and firmware
information for the selected module based on the corresponding connected module. The
module information page also provides the capability to perform a firmware update.
Viewing the Module Information page requires the "query diagnostics" privilege (Page 1005).
Module information: Status tab
The status tab in the bottom section of the module information page displays a description of
the current status of the module that is selected in the top section. If the section is empty,
then the module has no pending diagnostic state.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1023
Web server
12.6 Standard Web pages
Status icons for the modules
For each module, the status column of the top section displays an icon that indicates the
status of that module:
Icon
Meaning
No fault
Deactivated
Maintenance required
Maintenance demanded
Error
The CPU cannot reach the module or device (for devices other than the CPU)
The CPU has established a connection to the device, but the module status is unknown (for
devices other than the CPU)
Input and output data are unavailable because the submodule has blocked its I/O channels
(for devices other than the CPU)
Drilling down
You can select a link in the top section to drill down to the module information for that
particular module. Modules with submodules have links for each submodule. The type of
information that is displayed varies with the module selected. For example, the module
information dialog initially displays the name of the S7-1200 station, a status indicator, and a
comment. If you drill down to the CPU, the module information displays the name of the
digital and analog inputs and outputs that the CPU model provides, addressing information
for the I/O, status indicators, slot numbers, and comments.
As you drill down, the module information page shows the path you have followed. You can
click any link in this path to return to a higher level.
S7-1200 Programmable controller
1024
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Module information: Identification tab
The identification tab displays the Identification and Maintenance (I&M) information of the
selected module.
Note that if you click an F-I/O module in the top section, then the bottom section has a Safety
tab. On this tab, you can see specific data related to the selected module as described in the
S7-1200 Functional Safety Manual
(https://support.industry.siemens.com/cs/ww/en/view/104547552).
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1025
Web server
12.6 Standard Web pages
Module information: Firmware tab
The firmware tab of the module information page displays information about the firmware of
the selected module. If you have the "perform firmware update" privilege (Page 1005), you
can also perform a firmware update of the CPU or other modules in the local rack that
support firmware update. For remote modules, you can view the firmware information, but
not perform a firmware update.
Note
For updating CPU firmware, you can only update S7-1200 CPUs of version 3.0 and higher.
Performing a firmware update
The CPU must be in STOP mode to perform a firmware update. When the CPU is in STOP
mode, click the Browse button to navigate to and select a firmware file. Firmware updates
are available on the Siemens Industry Online Support Web site
(http://support.industry.siemens.com).
During the update, the page displays a message showing that the update is in progress.
After the update completes, the page displays the article number and version number of the
updated firmware. If you updated the firmware for the CPU or a signal board, the Web server
restarts the CPU.
You can also perform a firmware update by one of these methods:
● Using the online and diagnostic tools of STEP 7 (Page 1318)
● Using a SIMATIC memory card (Page 148)
● Using the SIMATIC Automation Tool
(https://support.industry.siemens.com/cs/ww/en/view/98161300)
S7-1200 Programmable controller
1026
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Note
Potential problems with performing a firmware update from the Web server
In the event of a communications disruption during a firmware update from the Web server,
your Web browser could display a message asking whether you want to leave or stay on the
current page. To avoid potential problems, select the option to stay on the current page.
If you close the Web browser while in the process of performing a firmware update from the
Web server, you will be unable to change the operating mode of the CPU to RUN mode. If
this situation happens, you must cycle power to the CPU to be able to change the CPU to
RUN mode.
12.6.9
Communication
The communication page displays the parameters of the connected CPU, communications
statistics, resources and information about connections.
Viewing the Communication page requires the "query diagnostics" privilege.
Parameter tab
The Parameter tab shows the MAC address of the CPU, the IP address and IP settings of
the CPU, and physical properties:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1027
Web server
12.6 Standard Web pages
Statistics tab
The Statistics tab shows send and receive communication statistics:
S7-1200 Programmable controller
1028
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Connection resources tab
The Resources tab shows information about the total number of connection resources and
how they are allocated for different types of communication:
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1029
Web server
12.6 Standard Web pages
Connection status tab
The Connections tab shows the connections for the CPU, and connection details for the
selected connection.
S7-1200 Programmable controller
1030
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.10
Tag status
The Tag status page allows you to view any of the I/O or memory data in your CPU. You can
enter a direct address (such as %I0.0), a PLC tag name, or a tag from a specific data block.
For data block tags, you enclose the data block name in double quotation marks. For each
monitor value you can select a display format for the data. You can continue entering and
specifying values until you have as many as you want within the limitations for the page. The
monitor values show up automatically. You can click the "Refresh" button at any time to
refresh all of the monitor values. If you have enabled automatic update in STEP 7
(Page 1003), you can click the "Off" icon in the upper right area of the page to disable it.
When automatic update is disabled, you can click "On" to re-enable it.
Viewing the Tag status page requires the "read tag status" privilege.
If you login as a user with the "write tag status" privilege (Page 1013), you can also modify
data values. Enter any values that you wish to set in the appropriate "Modify Value" field.
Click the "Go" button beside a value to write that value to the CPU. You can also enter
multiple values and click "Apply" to write all of the values to the CPU. The buttons and
column labels for modifying only appear if you have the "write tag status" privilege.
If you leave the Tag status page and return, the Tag status page does not retain your
entries. You can bookmark the page and return to the bookmark to see the same entries. If
you do not bookmark the page, you must re-enter the variables.
For values you frequently monitor or modify, consider using a Watch table (Page 1033)
instead.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1031
Web server
12.6 Standard Web pages
Note
Be aware of the following issues when using the standard Tag status page:
• Enclose all string modifications in single quotes.
• The Tag status page can monitor and modify tags that contain any of the following
characters: &, <, (, +, ,(comma), ., [, ], $, or %, providing you enclose the tag name in
double quotation marks, for example, "Clock_2.5Hz".
• To monitor or modify just one field of a DTL tag, include the field in the Address, for
example, "Data_block_1".DTL_tag.Year. Enter an integer value for the modify value
according to the data type of the specific field of the DTL. For example, the Year field is a
UInt.
• The maximum number of variable entries per page is 50.
• If a tag name displays special characters such that it is rejected as an entry on the Tag
status page, you can enclose the tag name in double quotation marks. In most cases, the
page will then recognize the tag name.
See also
Rules for entering tag names and values (Page 1084)
S7-1200 Programmable controller
1032
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.11
Watch tables
The Web server allows you to access watch tables that you have configured in STEP 7 and
which you have downloaded to the CPU. Watch tables with 50 or fewer entries offer the best
performance in the Web server.
STEP 7 configuration to select watch tables for the Web server
From the Device Configuration of the CPU in STEP 7, you can add the watch tables that you
want the Web server to be able to display. For each watch table that you select from the list
of existing watch tables, you select Read or Read/Write privileges for it. When downloaded
to the CPU, you can only view the watch tables that have the Read privilege but you can
view and modify watch table tags when you select the Read/Write privilege.
After you complete the watch table configuration in the Web server section of the device
configuration, download your hardware configuration to the CPU.
Viewing watch tables from the Web server
From the Web server, if you have the "read tags" privilege (Page 1005) you can select
"Watch tables" from the navigation menu to access the watch tables that you have
configured and downloaded to the CPU. If you have downloaded more than one watch table,
you can select the one you want to display from the drop-down list. The Web server displays
the watch table that you created in STEP 7 and the current values according to the display
format. You can change the display format if you choose, but when you return to the watch
table page the Web server defaults to the display formats in the STEP 7 watch table.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1033
Web server
12.6 Standard Web pages
Modifying watch table tags from the Web server
If you downloaded a watch table with the "Read/Write" access level, and you have logged in
to the Web server with the "write tags" privilege (Page 1005) you can also modify tag values
just like you do in a watch table in STEP 7. You can modify individual tag values and click
"Go" to modify only the one value, or you can enter several values and click "Apply" to
modify them all at once.
Note
Advantages of watch tables for modifying tags
In order for a user to modify tags and data block tags in the CPU from a watch table, you
must configure the watch table in the Web server properties in the STEP 7 device
configuration, and you must make it have Read/Write access. By so doing, you can restrict
the tags to which a user with the "write tags" privilege can modify to only those tags in the
configured Web server watch tables.
The Tag Status (Page 1031) page on the other hand allows any user with the "write tag
status" privilege to write to any tag or data block tag in the CPU.
By careful configuration of the Web server user management privileges (Page 1005), you
can help safeguard access to your PLC data.
See also
Rules for entering tag names and values (Page 1084)
S7-1200 Programmable controller
1034
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
12.6.12
Online backup
The Online backup standard Web page allows you to make a backup of the STEP 7 project
for the online PLC as well as to restore a previously-made backup of the PLC. Before
creating a backup or restoring a backup, place the PLC in STOP mode and cease all
communication with the PLC such as HMI access and Web server access. If your CPU is not
in STOP mode, the backup and restore functions prompt for confirmation to place the CPU in
STOP mode before continuing.
If you have accessed the Online backup page through one of the Web-enabled CP modules,
you can perform a backup but you cannot restore.
Note
You can also perform backup and restore operations from STEP 7 (Page 1352). Refer to
these topics for a full description of what data you can back up and restore. The SIMATIC
Automation Tool (SAT) also provides backup and restore capability.
When you back files up from the Web server, your PC or device saves the backup files in the
default folder for downloads. When you back files up from STEP 7, STEP 7 stores the files
within the STEP 7 project. You cannot restore STEP 7 backup files from the Web server and
you cannot restore Web server backup files from STEP 7. You can, however, save STEP 7
backup files directly to the download folder of your PC or device. If you do so, then you can
restore these files from the Web server.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1035
Web server
12.6 Standard Web pages
Backup PLC
From the Backup PLC section of the page, click the "Create online backup" button to make a
backup of the project that is currently stored in the PLC. This function requires the "Backup
CPU" user privilege (Page 1005). If the CPU is in RUN mode and you have to change it to
STOP mode, you also need the "Change operating mode" privilege. The PC or device will
store the backup file at the default location for downloads. Depending on your browser and
device settings, you might be prompted about saving the file.
Restore PLC
From the Restore PLC section of the page, enter the Web server user password and click
the "Browse" or "Choose File" button (depending on your browser) to select a previouslysaved backup file. Click the "Load online backup" button and confirm the prompt to load this
file in the connected PLC. This page requires the "Restore CPU" user privilege (Page 1005).
If the CPU is in RUN mode and you have to change it to STOP mode, you also need the
"Change operating mode" privilege.
As the restore operation proceeds, you see a series of progress messages and you must
reenter your user login and password. After each step of the process completes successfuly,
you see the following completion indicators and a link to reload the page:
WARNING
Restoring backups with unknown content
If you restore a backup with unknown content, you can cause serious damage or injuries in
case of malfunctions or program errors.
In addition, if you restore a backup that does not have the Web server enabled in the
device configuration of the CPU, you will not be able to access the CPU from the Web
server.
Make sure that the backup consists of a configuration with known content.
S7-1200 Programmable controller
1036
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Note
Restoring a backup where the CPU IP address is different
If you attempt to restore a backup where the CPU IP address in the backup is different from
the IP address of the current CPU, the Web server cannot display the message that the
restore is complete. After you see the "Reset CPU" message for greater than five minutes,
enter the new IP address that corresponds to the address in the backup file. The CPU now
has this address and you can resume Web server access.
12.6.13
File Browser
The File Browser page provides access to files in the internal load memory of the CPU or on
the memory card (external load memory). The file browser page initially displays the root
folder of the load memory, which contains the "DataLogs" and "Recipes" folders, but also
displays any other folders that you might have created, if using a memory card.
The type of file access you have to the files and folders depends on your user privileges
(Page 1005). Any user with "read files" privileges can view the files and folders with the file
browser. You cannot delete the DataLogs folder or Recipes folder regardless of your login
privileges, but if you had made custom folders on the memory card, you can delete those
folders if you have logged in as a user with "write/delete files" privileges.
Click a folder to access the individual files in the folder.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1037
Web server
12.6 Standard Web pages
Data logs
From the "Data Logs" folder, you can open any of the data log files. If you have logged in
with the "write/delete files" privilege (Page 1005), you can also delete, rename, and upload
files. The data log files are in comma-separated values (CSV) file format. You can save them
to your computer or open them in Microsoft Excel (default) or another program.
Note
Time stamps for data logs
The Web server displays the time stamps for the data logs in either UTC time or PLC local
time depending upon your selection at the top of the page.
Note: The "Delete" and "Rename" options are not available if you are not logged in with the
"write/delete files" privilege.
Note
Data log management
Keep no more than 1000 data logs in a file system. Exceeding this number can prevent the
Web server from having enough CPU resources to display the data logs.
If you find that the File Browser Web page is not able to display the data logs, then you must
place the CPU in STOP mode in order to display and delete data logs.
Manage your data logs to ensure that you only keep the number that you need to maintain,
and do not exceed 1000 data logs.
S7-1200 Programmable controller
1038
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.6 Standard Web pages
Working with a data log in Excel
The data log file is in USA/UK comma-separated values format (CSV). To open it in Excel on
non-USA/UK systems, you must import it into Excel with specific settings (Page 1086).
Recipe files
Like the data logs folder, the recipe folder displays any recipe files that are present in load
memory. Recipe files are also in CSV format, and you can open them in Microsoft Excel, or
another program. Like data logs, you must have modify privileges in order to delete, modify
and save, rename or upload recipe files.
Uploading files and automatic page refresh
If you begin a file upload, the upload operation continues as long as you remain on the File
Browser Web page. If you enabled automatic update to refresh the Web server pages every
ten seconds, then whenever a page refresh occurs you see the incremental progress of the
file upload operation. For example, if you are uploading a 2 MB file, you might see updates
that show the file size in bytes at 2500, 5000, 10000, 15000, and 20000 as the file upload
progresses.
If you leave the File Browser page before the upload completes, you do not get the complete
file. When you return, the File Browser page displays the file name and the size of the file at
the time that the upload stopped. You see no other indication that it is an incomplete file. To
be sure you upload the complete file, remain on the File Browser page until the displayed file
size reaches the actual size of the file.
Additional information
For information on programming with the data log instructions, and importing (Page 504) and
exporting (Page 502) recipes, see the Recipes and Data logs (Page 498) chapter.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1039
Web server
12.7 User-defined Web pages
12.7
User-defined Web pages
The S7-1200 Web server also provides the means for you to create your own applicationspecific HTML pages that incorporate data from the PLC.
WARNING
Unauthorized access to the CPU through user-defined Web pages
Unauthorized access to the CPU through user-defined Web pages could disrupt process
operation, which could result in death, severe personal injury and/or property damage.
Insecure coding of user-defined Web pages introduces security vulnerabilites such as
cross-site scripting (XSS), code injection, and others.
Protect your S7-1200 CPU from unauthorized access by installing it in a secure fashion as
outlined in the Operational Guidelines found on the Industrial Security Web site
(http://www.siemens.com/industrialsecurity).
You create user-defined Web pages using the HTML editor of your choice and download
them to the CPU where they are accessible from the standard Web page menu. This
process involves several tasks:
● Creating HTML pages with an HTML editor, such as Microsoft Frontpage (Page 1041)
● Including AWP commands in HTML comments in the HTML code (Page 1042):The AWP
commands are a fixed set of commands that Siemens provides for accessing CPU
information.
● Configuring STEP 7 to read and process the HTML pages (Page 1057)
● Generating blocks from the HTML pages (Page 1057)
● Programming STEP 7 to control the use of the HTML pages (Page 1059)
● Compiling and downloading the blocks to the CPU (Page 1060)
● Accessing the user-defined Web pages from your PC (Page 1061)
This process is illustrated below:
①
HTML files with embedded AWP commands
S7-1200 Programmable controller
1040
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.7 User-defined Web pages
12.7.1
Creating HTML pages
You can use the software package of your choice to create your own HTML pages for use
with the Web server. Be sure that your HTML code is compliant to the HTML standards of
the W3C (World Wide Web Consortium). STEP 7 does not perform any verification of your
HTML syntax.
You can use a software package that lets you design in WYSIWYG or design layout mode,
but you need to be able to edit your HTML code in pure HTML form. Most Web authoring
tools provide this type of editing; otherwise, you can always use a simple text editor to edit
the HTML code. Include the following line in your HTML page to set the charset for the page
to UTF-8:
Also be sure to save the file from the editor in UTF-8 character encoding.
You use STEP 7 to compile everything in your HTML pages into STEP 7 data blocks. These
data blocks consist of one control data block that directs the display of the Web pages and
one or more fragment data blocks that contain the compiled Web pages. Be aware that
extensive sets of HTML pages, particularly those with lots of images, require a significant
amount of load memory space (Page 1062) for the fragment DBs. If the internal load
memory of your CPU is not sufficient for your user-defined Web pages, use a memory card
(Page 138) to provide external load memory.
To program your HTML code to use data from the S7-1200, you include AWP commands
(Page 1042) as HTML comments. When finished, save your HTML pages to your PC and
note the folder path where you save them.
Note
The file size limit for HTML files containing AWP command is 64 kilobytes. You must keep
your file size below this limit.
Refreshing user-defined Web pages
User-defined Web pages do not automatically refresh. It is your choice whether to program
the HTML to refresh the page or not. For pages that display PLC data, refreshing periodically
keeps the data current. For HTML pages that serve as forms for data entry, refreshing can
interfere with the user entering data. If you want your entire page to automatically refresh,
you can add this line to your HTML header, where "10" is the number of seconds between
refreshes:
You can also use JavaScript or other HTML techniques to control page or data refreshing.
For this, refer to documentation on HTML and JavaScript.
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
1041
Web server
12.7 User-defined Web pages
12.7.2
AWP commands supported by the S7-1200 Web server
The S7-1200 Web server provides AWP commands that you embed in your user-defined
Web pages as HTML comments for the following purposes:
● Reading variables (Page 1044)
● Writing variables (Page 1045)
● Reading special variables (Page 1047)
● Writing special variables (Page 1048)
● Defining enum types (Page 1050)
● Assigning variables to enum types (Page 1051)
● Creating fragment data blocks (Page 1052)
General syntax
Except for the command to read a variable, the AWP commands are of the following syntax:
You use the AWP commands in conjunction with typical HTML form commands to write to
variables in the CPU.
The descriptions of the AWP commands in the following pages use the following
conventions:
● Items enclosed in brackets [ ] are optional.
● Items enclosed in angle brackets < > are parameter values to be specified.
● Quotation marks are a literal part of the command. They must be present as indicated.
● Special characters in tag or data block names, depending on usage, must be escaped or
enclosed in quotation marks (Page 1055).
Use a text editor or HTML editing mode to insert AWP commands into your pages.
Note
Expected syntax of AWP commands
The space after "" in the formulation of an AWP command
are essential to proper compiling of the command. Omission of the space characters can
cause the compiler to be unable to generate the proper code. The compiler does not display
an error in this case.
S7-1200 Programmable controller
1042
System Manual, V4.2, 09/2016, A5E02486680-AK
Web server
12.7 User-defined Web pages
AWP command summary
The details for using each AWP command are in the topics to follow, but here is a brief
summary of the commands:
Reading variables
:=:
Writing variables
This AWP command merely declares the variable in the Name clause to be writable. Your
HTML code performs writes to the variable by name from ,