SIMATIC NET Preface, Contents HARDNET Time-of-Day Function for PROFIBUS Introduction to the time-of-day functions of the CP 5613 1 Manual Programming interface for the time-of-day functions of the CP 5613 2 C79000-G8900-C254-01 Release 06/2011 Safety guidelines This manual contains notices which you should observe to ensure your own personal safety, as well as to protect the product and connected equipment. These notices are highlighted in the manual by a warning triangle and are marked as follows according to the level of danger: ! Danger indicates that death, severe personal injury or substantial property damage will result if proper precautions are not taken. ! Warning ! Caution indicates that death, severe personal injury or substantial property damage can result if proper precautions are not taken. indicates that minor personal injury or property damage can result if proper precautions are not taken. Note draws your attention to particularly important information on the product, handling the product, or to a particular part of the documentation. Qualified personnel Only qualified personnel should be allowed to install and work on this equipment. Qualified persons are defined as persons who are authorized to commission, to ground, and to tag circuits, equipment, and systems in accordance with established safety practices and standards. Correct usage Note the following: ! Warning This software may only be used for the applications described in the catalog or the technical description, and only in connection with devices or software products from other manufacturers which have been approved or recommended by Siemens. This product can only function correctly and safely if it is transported, stored, set up, and installed correctly, and operated and maintained as recommended. Trademarks SIMATIC(R) and SIMATIC NET(R) are registered trademarks of Siemens AG. Third parties using for their own purposes any other names in this document which refer to trademarks might infringe upon the rights of the trademark owners. Copyright Siemens AG 2011, All rights reserved The reproduction, transmission or use of this document or its contents is not permitted without express written authority. Offenders will be liable for damages. All rights, including rights created by patent grant or registration of a utility model or design, are reserved. Siemens AG Bereich Automatisierungs- und Antriebstechnik Geschaftsgebiet Industrie-Automatisierungssysteme Postfach 48 48, D-90327 Nurnberg Siemens Aktiengesellschaft Disclaimer We have checked the contents of this manual for agreement with the hardware and software described. Since deviations cannot be precluded entirely, we cannot guarantee full agreement. However, the data in this manual are reviewed regularly and any necessary corrections included in subsequent editions. Suggestions for improvement are welcomed. C79000-G8900-C254-01 (c) Siemens AG 2011 Technical data subject to change. 2 Preface Purpose of the document This document supports you when linking user programs to the time-of-day functions of the CP 5613 communications processor. It applies to the SIMATIC communications processors CP 5613, CP 5614, CP 5613 FO, CP 5614 FO, CP 5613 A2, CP 5614 A2, CP 5603, CP 5623 and CP 5624, that are always called "CP 5613" on the following pages. The purpose and mechanisms of the time-of-day functions are explained and typical communications partners are listed. The programming of the time-of-day functions is described based on two examples. Aims With the information in this manual, you will be able to integrate the program calls described here into your programs. We assume that you are thoroughly familiar with your programs and development environment. Further support If you have other questions on SIMATIC products please contact the Siemens representative for your area. You will find the addresses on the Internet at the following address: http://www.siemens.com/automation/partner Online support In addition to our product documentation, the comprehensive online information platform throughout our Service & Support is available to you at all times wherever you are in the world. You will find this on the Internet at the following address: www.siemens.com/automation/service&support HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 3 Preface There, you wil find the following information: Support news, newsletter Product information, product support, applications & tools Technical forum Access to our other Service & Support offers: - Technical consulting - Engineering support - Field service Telephone: +49 (0)911 895 7444 - Spare parts and repairs Telephone: +49 (0)911 895 7448 - Optimization and modernization - Technical support Expert consultation in technical questions with a wide range of services tailored to our entire products and systems. Telephone: +49 (0)911 895 7222 www.siemens.de/automation/support-request You will find contact data on the Internet at the following address: http://www.automation.siemens.com/partner SITRAIN - Siemens Training for Automation and Industrial Solutions With over 300 different courses, SITRAIN covers the entire Siemens product and system spectrum in the field of automation and drive technology. Advanced training tailored to your needs is also available. In addition to our classic range of courses, we also offer a combination of various training media and sequences. You can, for example, use self-study programs on CD-ROM or on the Internet as preparation for and to consolidate training. You will find detailed information on our training curriculum and how to contact our customer consultants at the following Internet address: www.siemens.de/sitrain HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 4 HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 6 Contents 1 2 Introduction to the time-of-day functions of the CP 5613 .......................................... 8 1.1 Operating a PC with a CP 5613 as a time-of-day receiver ................................. 9 1.2 Operating a PC with a CP 5613 as a time transmitter ...................................... 10 1.3 Operating a PC with a CP 5613 as standby master.......................................... 11 Programming interface for the time-of-day functions of the CP 5613 .................... 12 2.1 2.1.1 Receiving the time-of-day.................................................................................. 13 2.1.1 Explanation of the bits in the scp_status component ............................... 15 2.2 Sending the time-of-day .................................................................................... 18 HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 7 Introduction to the time-of-day functions of the CP 5613 1 With the time-of-day functions of the CP 5613, you can achieve the following: You can operate a PC as a time-of-day receiver so that you have a uniform time (absolute time) in a PROFIBUS network. You can operate a PC as a time-of-day transmitter to supply other stations within a PROFIBUS network with a uniform time-of-day (absolute time). You can operate a PC as the standby master; in other words, as a standby time-of-day transmitter that becomes active if the main time-of-day transmitter fails. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 8 Introduction to the time-of-day functions of the CP 5613 1.1 Operating a PC with a CP 5613 as a time-of-day receiver Communication partners A PC with a CP 5613 can receive time-of-day frames from the following time transmitters via PROFIBUS: SIMATIC S7 AS 300 and SIMATIC S7 AS 400 which provide the time-of-day transmitter functionality PC with CP 5613 communications processor Accuracy and synchronization mechanisms As a time-of-day receiver the CP 5613 maintains an accuracy of 20 ms between PROFIBUS and the user program. The CP 5613 checks the relative accuracy of the received time-of-day frames by waiting until several frames have been received and then checking the deviations. Synchronization only takes place when the deviations are within the permitted range: a frame was received every 60 s 1 s. the fluctuation in the times contained in the frames is below 2 s. Update time The update time is the time that elapses between a time transmitter sending two consecutive time-of-day frames. Multiples of the update time must result in 60 s to allow the CP 5613 to be successfully synchronized. Valid update times could be, for example 5 s, 10 s, or 60 s. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 9 Introduction to the time-of-day functions of the CP 5613 1.2 Operating a PC with a CP 5613 as a time transmitter Communication partners A PC with a CP 5613 as time-of-day transmitter can send time-of-day frames to the following typical receivers: SIMATIC S7 AS 300 and SIMATIC S7 AS 400 which provide the time-of-day transmitter functionality PC with CP 5613 communications processor Origin of the precise time-of-day The real time clocks in PCs are not suitable for providing the time to a highly accurate time-of-day transmitter. Using the following services, a user program can obtain a highly accurate time-of-day: GPS (Global Positioning System) or DCF77 (radio reception of the atomic clocks in Braunschweig, Germany for central Europe) Suitable PC peripheral devices are commercially available. Synchronization mechanisms and increased accuracy The transmission of the time-of-day by the CP 5613 is divided into two steps: Transfer of the time-of-day from the user program to the CP 5613 without a time-of-day frame being sent via the PROFIBUS network. The CP 5613 automatically continues to update the time-of-day. Transmitting of frames with the maintained time-of-day to the PROFIBUS network. This step is handled automatically by the CP 5613. Update time How often a time-of-day frame is transmitted on the network is controlled by the user program. The CP 5613 sends a time-of-day frame at least every 60 s. If the CP 5613 detects a deviation between its onboard maintained time-of-day and the time transferred by the user program, it reduces the interval down to a minimum of 5 seconds. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 10 Introduction to the time-of-day functions of the CP 5613 Addressing The CP 5613 assigns the recipient broadcast address 7Fh to the time-of-day frames it sends. This recipient address cannot be altered. 1.3 Operating a PC with a CP 5613 as standby master Purpose of a standby master A standby master is a substitute time-of-day transmitter that becomes active if the primary master fails. How a standby master functions If several CP 5613 processors are operating as time master, only the CP 5613 with the lowest bus address sends time-of-day frames. The other CP 5613 processors, do not send any time-of-day frames even if their user programs request this. Based on the status of the time transmitter, a user program can recognize whether or not a time master with a lower bus address is sending time-of-day frames (refer to section 2.1). HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 11 Programming interface for the time-of-day functions of the CP 5613 2 This chapter explains how a program can make use of the time-of-day functions of the CP 5613. The explanation refers to a sample program, that demonstrates reception and sending of the time-of-day. You should leave all the parameters of the sample program unchanged unless a change is described. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 12 Programming interface for the time-of-day functions of the CP 5613 2.1 Receiving the time-of-day Overview of the sequence for receiving the time-of-day Step Description 1 Open a communication channel to the driver of the CP 5613 (SCP_open call) 2 Complete a request block for receiving the time-of-day. 3 Send the request block to the driver of the CP 5613 (SCP_send call) 4 Adopt the supplied time-of-day, when necessary return to Step 2 5 Close the communication channel to the driver of the CP 5613 (SCP_close call) This sequence is as an example programmed in the "timeread.c" file that you will find in the same folder as this description. You will also find the header file "Fdl_rb.h" in which the prototypes of the functions and required data structures are declared. Explanation of step 1: SCP_open call With this call, you open a communications channel to the driver of the CP 5613. The only function argument is a string with the name of the CP 5613 (access point of the application, for example," CP5613(PROFIBUS)"). How the names of the CP 5613 communications modules are assigned is described in the installation instructions of your product. A handle is returned that must be used for further SCP calls. For information on dealing with errors, refer to the sample program. Explanation of step 2: Completing a request block Your user program should declare and complete the "time_rb" request block as described in the sample program. Explanation of step 3: Sending the request block to the driver of the CP 5613 With the SCP_send call, you send the request block to the driver of the CP 5613. The arguments are the handle returned in the first step and the length and address of the "time_rb" request block. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 13 Programming interface for the time-of-day functions of the CP 5613 For information on dealing with errors, refer to the sample program. Explanation of step 4: Accepting the supplied time-of-day After successful completion, the following information is available: Time since the beginning of the day in milliseconds in the "time" component in big endian format. Date in days since 1.1.1984 in the "date" component in big endian format. Status of the time-of-day recipient in the "scp_status" component in little endian format (see below). Status of the time-of-day transmitter in the "transmitter_status" component in big endian format (time-of-day recipient) or in little endian format (time transmitter). Refer to the documentation of your time transmitter; if the CP 5613 is operating as time transmitter, check the value of the "transmitter_status" parameter in the transmission example. The "transmitter_status" value is only valid if time signaling is synchronized, in other words, the SYNC bit is set in "scp_status". To convert the time-of-day format to a structure that is more suitable for further processing, you can use the SCI_conv_time() function as shown in the sample program. In the sample program, the time-of-day and date are then output in detail. You can replace this section with your own program for further processing of the time. Explanation of step 5: Closing the communications channel With the SCP_close call, you close the communications channel to the driver of the CP 5613. The only argument is the handle returned with the SCP_open call. Closing the communications channel is not necessary each time the time-of-day has been read and can be done when you close your user program. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 14 Programming interface for the time-of-day functions of the CP 5613 2.1.1 2.1.1 Explanation of the bits in the scp_status component Definition of "scp_status" The 16-bit word "scp_status" describes the time-of-day status on the CP 5613. It can be read by the user program. Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 CP_5613 reserved reserved reserved reserved MASTER_ CONFLICT Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 reserved reserved SYNC RESOLUTION Bit 9 Bit 8 Mode of operation Bit 1 SYNC_ERR NO_SYNC_ IMP Bit 0 reserved The values of the "reserved" bits are undefined; in other words, they can be 0 or 1. The individual bits of "scp_status" are described below: Bit 1 - NO_SYNC_IMP (no synchronization pulse) The "NO_SYNC_IMP" signals waiting for the next time-of-day frame. Following each received time-of-day frame, the bit is off for 10 seconds. Value Description 0 Synchronization frame arrived 1 Wait for synchronization frame HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 15 Programming interface for the time-of-day functions of the CP 5613 Bit 2 - SYNC_ERR (synchronization error) The "SYNC_ERR" bit is set if a time-of-day frame contains a time outside the valid range. Value Description 0 Synchronization OK 1 Synchronization bad Bits 3 and 4 - RESOLUTION (time resolution) The RESOLUTION bits specify the intervals in which the time is updated. On the CP 5613, the time is updated every 10 ms so that the value for the resolution is constantly 01B. Value Description 00B 1 ms 01B 10 ms 10B 100 ms 11B 1s Bit 5 - SYNC (time synchronized) The SYNC bit specifies whether the time on the CP 5613 is currently synchronized with the time of a time transmitter. This bit is set when the clock on the CP 5613 matches the time in the synchronization frames of the time transmitter within the limits of accuracy; in other words, within the range of tolerance of 20 ms. If three consecutive expected synchronization frames are lost or are not within the range of tolerance, this bit is reset. Value Description 0 Not synchronized 1 Synchronized HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 16 Programming interface for the time-of-day functions of the CP 5613 Bit 8 to 9 - Mode of operation The mode for keeping time on the module is coded in these bits: Value Description 00B Time keeping off 01B Time slave 10B Time master 11B reserved Bit 10 - MASTER_CONFLICT This bit indicates whether or not a second time transmitter with a lower bus address is sending time-of-day frames. In this case the CP 5613 suppresses the sending of time-of-day frames. Value Description 0 Only time transmitter on the bus. 1 Second time transmitter with a lower bus address is active, therefore sending of time-of-day frames is not possible. Bit 15 - CP_5613 (module identifier) This bit indicates the module type. The CP 5613 returns the constant value 1. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 17 Programming interface for the time-of-day functions of the CP 5613 2.2 Sending the time-of-day Overview of the sequence for sending the time-of-day As explained in section 1.2, the time-of-day is sent automatically after it is transferred to the CP 5613 (step 2 and 3 below). Step Description 1 Open a communication channel to the driver of the CP 5613 (SCP_open call) 2 Complete a request block for the transfer of the time-of-day to the CP 5613 3 Send the request block to the driver of the CP 5613 (SCP_send call), following this if required return to step 2. 4 Close the communication channel to the driver of the CP 5613 (SCP_close call) Your user program should execute steps 2 and 3 at least every 10 seconds; in other words,transfer the precise time-of-day again to avoid losing the required accuracy. This sequence is programmed as an example in the "timesend.c" file that you will find in the same folder as this description. You will also find the header file "Fdl_rb.h" in which the prototypes of the functions and required data structures are declared. Explanation of step 1: SCP_open call With this call, you open a communications channel to the driver of the CP 5613. The only function argument is a string with the name of the CP 5613 (for example,"CP5613(PROFIBUS)"). How the name of your CP 5613 is specified is explained in the installation instructions for your product. For information on dealing with errors, refer to the sample program. Explanation of step 2: Completing a request block for transferring the time-of-day Your user program should declare and complete the request block "time_rb" exactly as described in the sample program apart from the actual times. The set "transmitter_status" component is application-specific and is not modified by the CP 5613. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 18 Programming interface for the time-of-day functions of the CP 5613 With the "scp_status" component, the user program controls whether or not the CP 5613 automatically sends time-of-day frames. Bit 11 activates (bit 11 = 1) or terminates (bit 11 = 0) automatic sending. With bit 5, the user program controls whether the "transmitter_status" component is included in the time-of-day frame (bit 5 = 1) or not (bit 5 = 0). The last time the time is transferred prior to exiting the user program, automatic sending must also be terminated. Refer to the example program. Please note that in contrast to reading the time-of-day, the "transmitter_status" component must be written in little endian format. Explanation of step 3: Transferring the request block to the driver of the CP 5613 With the SCP_send call, you send the request block to the driver of the CP 5613. The arguments are the handle returned in the first step and the length and address of the "time_rb" request block. For information on dealing with errors, refer to the sample program. Explanation of step 4: Closing the communications channel With the SCP_close call, you close the communications channel to the driver of the CP 5613. The only argument is the handle returned with the SCP_open call. Closing the communications channel is not necessary each time the time-of-day has been sent and can be done when you close your user program. HARDNET Time-of-Day Function for PROFIBUS C79000-G8900-C254-01 19