Using S7 Cpus As SNTP Servers: S7-1500, S7-1200, S7-400, S7-300
Using S7 Cpus As SNTP Servers: S7-1500, S7-1200, S7-400, S7-300
Using S7 Cpus As SNTP Servers: S7-1500, S7-1200, S7-400, S7-300
Using S7 CPUs
as SNTP Servers
S7-1500, S7-1200, S7-400, S7-300
http://support.automation.siemens.com/WW/view/en/82203451
Warranty and Liability
Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. The Application
Examples do not represent customer-specific solutions. They are only intended
to provide support for typical applications. You are responsible for ensuring that
the described products are used correctly. These Application Examples do not
relieve you of the responsibility to use sound practices in application, installation,
operation and maintenance. When using these Application Examples, you
recognize that we cannot be made liable for any damage/claims beyond the
liability clause described. We reserve the right to make changes to these
Application Examples at any time without prior notice. If there are any deviations
between the recommendations provided in these Application Examples and
other Siemens publications – e.g. Catalogs – the contents of the other
documents have priority.
We do not accept any liability for the information contained in this document.
Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act ("Produkthaftungsgesetz"), in case of intent, gross negligence, or injury of life,
Copyright Siemens AG 2013 All rights reserved
Important
This document contains information on registry editing. We recommend creating a
safety copy of the registry before editing it. For further information on how to create
a safety copy, restore and edit the registry, please refer to the Microsoft Knowledge
Base article no. 256986. Incorrect use of the Registry Editor might cause serious
problems affecting the entire system and requiring new installation. Use the
Registry Editor on your own responsibility.
Caution
The functions and solutions described in this entry predominantly confine
themselves to the realization of the automation task. Please also take into account
that corresponding protective measures have to be taken in the context of
Industrial Security when connecting your equipment to other parts of the plant, the
enterprise network or the Internet. For more information, please refer to entry ID
50203404.
http://support.automation.siemens.com/WW/view/en/50203404
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 2
Table of Contents
Table of Contents
Warranty and Liability ................................................................................................. 2
1 Library Overview ................................................................................................ 4
1.1 User scenario ....................................................................................... 5
1.2 Hardware and software requirements .................................................. 6
1.3 Library resources .................................................................................. 7
2 Preconditions for Time Synchronization ........................................................ 8
2.1 System time (UTC) and local time ....................................................... 8
2.2 Time synchronization protocol ............................................................. 9
2.2.1 Network Time Protocol (NTP) .............................................................. 9
2.2.2 Simple Network Time Protocol (SNTP) ................................................ 9
2.3 Open User Communication ................................................................ 10
3 Blocks of the Library ....................................................................................... 11
3.1 Block list ............................................................................................. 11
3.2 Explanation of the blocks ................................................................... 11
3.2.1 Statuses of the SNTP_Serv FB (FB1000) .......................................... 11
3.2.1 Calling and parameters of the SNTP_SERV FB (FB1000) for
S7-1500/S7-1200 ............................................................................... 12
3.2.2 Calling and parameters of the SNTP_SERV FB (FB1000) for
S7-300/S7-400 ................................................................................... 14
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 3
1 Library Overview
1.1 User scenario
1 Library Overview
What you get
This document describes the "S7_CPU_SNTPServer" block library. This block
library includes a tested code with well-defined interfaces. You can use these as
basis for your projected task.
A key concern of the document is to describe
• all blocks pertaining to the block library,
• the functionalities provided by these blocks.
Furthermore, this documentation shows possible fields of application and helps you
integrate the library into your STEP 7 project using step-by-step instructions.
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 4
1 Library Overview
1.1 User scenario
Scenario
The following figure shows a possible sample configuration with an S7-1200 CPU
Copyright Siemens AG 2013 All rights reserved
as SNTP server. Here, the S7 CPU as SNTP server receives the time via a
SIPLUS DCF77 module (for the coupling of the DCF77 module to S7-1200, please
refer to \11\). However, any other configuration with a different timer is also
possible.
Figure 1-1
Comfort Panel
(NTP Client) S7-1500
(NTP Client)
PROFINET / IE
SIPLUS DCF 77 S7-1200
Radio Clock Module (SNTP Server)
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 5
1 Library Overview
1.2 Hardware and software requirements
Function
The library provides a function block that accomplishes the following functions:
• Receipt and analysis of an NTP message from an SNTP client.
• Creation and sending of an SNTP message to the client for time
synchronization.
Hardware
The "S7_CPU_SNTPServer" library can be used with all PROFINET S7 CPUs with
which Open User Communication (OUC) can be programmed.
This can be CPUs of the following series:
• S7-300 CPUs
• S7-400 CPUs
Copyright Siemens AG 2013 All rights reserved
• S7-1200 CPUs
• S7-1500 CPUs
• WinAC RTX
Software
Table 1-1
Component Order number
SIMATIC STEP 7 V5.5 SP3 6ES77810-4CC10-0YA5
SIMATIC STEP 7 PROFESSIONAL V12 SP1 6ES7822-1AA02-0YA5
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 6
1 Library Overview
1.3 Library resources
Total occupancy
The block pertaining to the "S7_CPU_SNTPServer" library occupies 4776 bytes of
the main memory at the maximum (S7-300/S7-400) and 33472 kbytes of the load
memory at the maximum (S7-1200/S7-1500).
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 7
2 Preconditions for Time Synchronization
2.1 System time (UTC) and local time
When the time of these CPUs is synchronized via an NTP/SNTP server, the UTC is
applied as system time and the local time is calculated automatically, based on the
settings made (also see chapter 5.2).
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 8
2 Preconditions for Time Synchronization
2.2 Time synchronization protocol
Task
NTP serves for the synchronization of clocks in a network. PCs, panels, controls,
etc. can synchronize time via a (or several) server(s).
Function principle
An NTP client sends a message which is already assigned time stamps to the NTP
server. The server responds to this message (by using an algorithm, for example,
to consider packet runtimes) and the client then sets its clock according to the
information received in the message.
An NTP client can have several time servers entered. Based on the "stratum"
entered in the message and other factors, the client decides in favor of the optimal
server and sends the request message to it.
SNTP is a simplified form of the NTP. Due to the simpler algorithms used, the
SNTP is less accurate than the NTP. However, for the use in automation cells, the
accuracy of the SNTP time synchronization is usually absolutely sufficient.
The structure of the messages is identical in both protocols, which means that NTP
clients can also obtain the time from SNTP servers.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 9
2 Preconditions for Time Synchronization
2.3 Open User Communication
Using SNTP
Since its implementation is easy and its accuracy is sufficient for automation
technology, the SNTP is used by the "S7_CPU_SNTPServer" library.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 10
3 Blocks of the Library
3.1 Block list
Internally, the SNTP_SERV FB (FB 1000) works as a simple state machine which
Copyright Siemens AG 2013 All rights reserved
Figure 3-1
Parameters
1 initialized
Initialize parameters;
set state = 0
2
Initialize
UDP connection
Create SNTP
4 Connection
message and send initialized
message to client
3
Receive
NTP message from
NTP client
Wait for
Message receipt
received
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 11
3 Blocks of the Library
3.2 Explanation of the blocks
Table 3-1
No. Action
1. The FB is called with Startup = TRUE for one cycle and the parameters of the FB
are initialized.
2. The local communication access point is set up at port 123 (TCON instruction).
3. The request message from an NTP client is awaited (TURCV instruction).
4. When the time request from an NTP client has been detected, the response
message is created and then sent to the client (TUSEND).
5. Afterwards, a new request message is awaited again (from the same or a
different client; -> status 3).
From any status it can be returned to the initialization status with another change of
edge at the Startup = TRUE input.
The following figure shows the call interface of the SNTP_SERV FB (FB1000). The
table describes the parameters of the function block.
Table 3-2
Parameter Type Remark
Startup IN: Upon CPU startup, the Startup parameter has to
Bool be supplied with "TRUE" for one cycle.
After a positive edge at "Startup", all parameters
of the SNTP_SERV FB are initialized.
ReferenceIdentifier IN: The ReferenceIdentifier input specifies from
USInt which time source the server CPU obtains the
time:
• 0: uncalibrated (set "manually")
• 1: primary reference (e.g., DCF 77)
• 2: secondary reference (e.g., from GPS
receiver)
The information is forwarded to the NTP client in
the SNTP protocol.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 12
3 Blocks of the Library
3.2 Explanation of the blocks
The table below shows the meaning of the "STATUS" output parameter.
Table 3-3 STATUS output parameter
Byte 2-3 Byte 0-1 Meaning
16#xxx1 16#xxxx An error has occurred at the TCON instruction.
Copyright Siemens AG 2013 All rights reserved
Note Interconnect the output parameters in order to recognize an error of the block
and for adequate error handling.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 13
3 Blocks of the Library
3.2 Explanation of the blocks
The following figure shows the call interface of the SNTP_SERV FB (FB1000). The
table describes the parameters of the function block.
Table 3-4
Parameter Type Remark
Startup IN: Upon CPU startup, the Startup parameter has to
Bool be supplied with "TRUE" for one cycle.
Copyright Siemens AG 2013 All rights reserved
The table below shows the meaning of the "STATUS" output parameter.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 14
3 Blocks of the Library
3.2 Explanation of the blocks
Note Interconnect the output parameters in order to recognize an error of the block
and for adequate error handling.
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 15
4 Working with the Library
4.1 Integrating the library into STEP 7 V5.5
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 16
4 Working with the Library
4.1 Integrating the library into STEP 7 V5.5
Step Instruction
6. Select the S7 program of the library and insert it into your STEP 7 project using
drag & drop.
7. Now you can use the blocks of the library in your user program. The other blocks
apart from the SNTP_SERV FB (FB1000) are function blocks used by this block.
Section 4.4 describes how to set up an S7 CPU as SNTP server in STEP 7 V12.
Setup in STEP 7 V5.5 is done analogously.
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 17
4 Working with the Library
4.2 Integrating the library into STEP 7 V12
Table 4-2
No. Instruction
1. The library is available on the HTML page from which you downloaded this
document (\1\). Save the S7_CPU_SNTPServer_V12.ziplibrary on your hard
disk.
2. Unzip the library.
3. Open your already existing STEP 7 V12 project.
4. In the "Global Libraries" palette, click on "Open global library" in the toolbar or
select "Global libraries > open library..." in the "Options" menu.
Copyright Siemens AG 2013 All rights reserved
6. Depending on the CPU used, drag and drop the blocks from the "Master copies >
300/400" or "Master copies > 1200/1500" folder to the Program blocks" folder of
your device.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 18
4 Working with the Library
4.3 Setting up an S7-1500/S7-1200 CPU as SNTP server
2. Insert the SNTP_SERV FB (FB1000) into OB1 and interconnect the input and
output parameters with the parameters of the same name of the data block
created in step 1. For help, please refer to section 3.2.1.
Adapt the input parameters according to your application (for example, the
connection ID "OUC_Con_ID" must not yet be used in the project).
3. Insert a startup OB (OB100) into your project and in this OB reset the "Startup"
Copyright Siemens AG 2013 All rights reserved
4. Insert a new network into OB1 and there reset the "Startup" variable of the block
created in step 1.
5. Load your user program to the CPU and restart the CPU. The CPU then works
as SNTP server.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 19
4 Working with the Library
4.4 Setting up an S7-400/S7-300 CPU as SNTP server
2. Insert the SNTP_SERV FB (FB1000) into OB1 and interconnect the input and
output parameters with the parameters of the same name of the data block
created in step 1.
Adapt the input parameters according to your application. For help, please refer
Copyright Siemens AG 2013 All rights reserved
to section 3.2.2.
• OUC_Con_ID: ID not yet occupied by another connection.
• LocDevID: ID of the interface of your CPU. Please refer to the STEP 7 online
help.
3. Insert a startup OB (OB100) into your project and in this OB reset the "Startup"
variable of the block created in step 1.
4. Insert a new network into OB1 and there reset the "Startup" variable of the block
created in step 1.
5. Load your user program to the CPU and restart the CPU. The CPU then works
as SNTP server.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 20
5 Notes and Support
5.1 Timer
Table 5-1 Setting the time of an S7-1500 CPU with the help of STEP 7 V12
No. Instruction
1. In your project tree, double-click on "Online access >
[YOUR_NETWORK_DEVICE] > Update accessible devices".
Copyright Siemens AG 2013 All rights reserved
2. Select the CPU for which you want to set the time and click on "Online &
diagnostics".
3. In the editor section, click on "Functions > Set time". Check the "Take from
PG/PC" box and then click on "Apply".
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 21
5 Notes and Support
5.2 Setting up an S7-1500/S7-1200 as NTP client
2
1
3
Copyright Siemens AG 2013 All rights reserved
3. Then go to the entry "Time of day" ( ) and adjust the time zone ( ) and the
difference between standard and daylight savings time ( ).
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 22
5 Notes and Support
5.2 Setting up an S7-1500/S7-1200 as NTP client
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 23
5 Notes and Support
5.3 Setting up an S7-300/S7-400 as NTP client
2
1
3
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 24
5 Notes and Support
5.3 Setting up an S7-300/S7-400 as NTP client
Table 5-4
No Instruction
.
1. Add a data block of the "WS_RULES" type to your user program.
2. Set the default values of the data block dependent on your time zone. When
inserting the data block into STEP 7 V12, the default values are preset to CET with
daylight savings time changeover. For more help on the values, please refer to the
STEP 7 help.
Copyright Siemens AG 2013 All rights reserved
3. Then first read out the system time with the RD_SYS_T block.
4. Call the BT_LT instruction and transfer the current system time as well as the data
block created in steps 1 + 2.
The instruction returns the local time. Save this time in such a way that it can be
accessed CPU-wide. Thus, diagnostic messages etc. can be supplied with the local
time as time stamp.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 25
5 Notes and Support
5.4 Setting up Windows PCs as NTP clients
3. Go to "Start > run" and enter "regedit" in the dialog window. Confirm with OK.
4. Navigate to the
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameter
s" folder and set the "NtpServer" key to the following value:
"[IP_ADRESSE_DER_SERVER_CPU],0x7B".
5. Go to "Start > run" and enter "cmd" in the dialog window. Confirm with OK.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 26
5 Notes and Support
5.4 Setting up Windows PCs as NTP clients
No Instruction
.
6. Enter the command "w32tm /confg /update" in the command line and confirm with
Return. Windows thus refreshes the settings.
7. Now enter the command "w32tm /resync" and confirm with Return. Thus, the time is
requested via NTP from the server entered in step 3 for the first time.
Note Make sure that port 123 is opened in the firewall of your PC.
Windows 7
Copyright Siemens AG 2013 All rights reserved
The following table describes the procedure for setting up a PC as NTP client
under Windows 7.
Table 5-6
No Instruction
.
1. Go to "Start" and enter "services.msc" in the search line. Confirm with Return.
A "Services" window opens.
2. Select the "Windows Time" service and start the service via the blue link if it has not
started yet.
Additionally set the service to "Automatic" so that it is started automatically by the
operating system upon each ramp-up.
3. Go to "Start" and enter "regedit" in the search line. Confirm with Return.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 27
5 Notes and Support
5.4 Setting up Windows PCs as NTP clients
No Instruction
.
4. Navigate to the
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Paramet
ers" folder and set the "NtpServer" key to the following value:
"[IP_ADRESSE_DER_SERVER_CPU],0x7B".
5. Go to "Start" and enter "cmd" in the search line. Execute the command line with
administrator rights. Confirm with "Yes".
6. Enter the command "w32tm /confg /update" in the command line and confirm with
Return. Windows thus refreshes the settings.
7. Now enter the command "w32tm /resync" and confirm with Return. Thus, the time is
requested via NTP from the server entered in step 3 for the first time.
Note Make sure that port 123 is opened in the firewall of your PC.
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 28
5 Notes and Support
5.5 Setting up HMI panels as NTP clients
Table 5-7
No. Instruction
1. Open the "Control Panel".
2. Open the "Profinet" dialog with the "PROFINET IO" icon. Go to the "NTP" tab.
3. Activate "Automatically synchronize with a time server" and enter an update rate.
Copyright Siemens AG 2013 All rights reserved
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 29
6 References
6 References
Table 6-1
Subject Title
\1\ Siemens Industry Online Support http://support.automation.siemens.com
\2\ Download page of the entry http://support.automation.siemens.com/WW/view
/en/79047707
\3\ STEP 7 Professional V12.0 SP1 http://support.automation.siemens.com/WW/view
/en/77991795
System Manual
\4\ Description of the SNTP Protocol http://tools.ietf.org/html/rfc4330
\5\ Siemens Mall: SIPLUS DCF 77 https://eb.automation.siemens.com/mall/en/WW/
Catalog/Product/6AG1057-1AA03-0AA0
\6\ Online Support: SIPLUS DCF 77 http://support.automation.siemens.com/WW/view
/en/26339574
\7\ FAQ: "How can you determine the http://support.automation.siemens.com/WW/view
coordinates and synchronize the /en/42087405
system time of the S7-1200 using a
commercially available GPS
receiver?"
\8\ FAQ: "Which STEP 7 standard http://support.automation.siemens.com/WW/view
blocks are available for time /en/15249609
stamping and time-of-day
Copyright Siemens AG 2013 All rights reserved
synchronization?"
\9\ FAQ: "How can you calculate the http://support.automation.siemens.com/WW/view
actual local time (summer time or /en/19324378
winter time) in the S7-300/400 CPU
and then use it on the panel as
system time?"
\10\ Windows Time Service Tools and http://technet.microsoft.com/pt-
Settings pt/library/cc773263(v=ws.10).aspx
7 History
Table 7-1
Version Date Modifications
V1.0 11/2013 First version
S7_CPU_SNTPServer
Entry ID: 82203451, V1.0, 10/2013 30