show the entry list

STEP 7 -- Creating S7 programs -- Editing date, time and counters  
Time synchronization - Time synchronization in the automation environment 
How can you set the time of an S7 controller from WinCC? 
Which functions are available in STEP 7 V5.5 and in TIA Portal for processing the data types DT and DTL? 
Which STEP 7 standard blocks are available for time stamping and time-of-day synchronization? 
How is the runtime of a terminal device (pump, for example) calculated? 
What is the modified Julian date and how can you calculate it with STEP 7? 
Tips and tricks for reading and comparing date, time and counters 
How do you convert an available seconds value into days, hours, minutes and seconds? 
Information about the topic of "Editing date and time" 
How can you measure the time? 
How do you program a timer that retains the time value at STOP and counts on starting at the stored value? 
How can you set the time of an S7-300 CPU via Industrial Ethernet and via MPI? 
How do you load the IEC standard functions FC3, FC6, FC7 and FC8 from the STEP 7 IEC library? 
How can you use IEC functions to read and input the date and time of the CPU? 
How can you synchronize CPU clocks with each other? 
How can you count forwards and backwards in a bandwidth between -2147483648 and +2147483647? 
How can you read out the date and time with SFC1 (READ_CLK) and input them with SFC0 (SET_CLK)? 
How can you create a timer for the "S7" without using an "S7 Timer"? 

Time synchronization - Time synchronization in the automation environmentGo to beginning
Part number:

Time synchronization
Time synchronization in the automation environment

Here you can go directly to the most important entries concerning "Time synchronization" in the Industry Online Support.
 

Time synchronizations procedures      
SIMATIC S7 NTP SINAUT ST7 User program HMI/PCS 7 Products Tools/Info

Time synchronization with the SIMATIC procedure

The SIMATIC procedure for time synchronization is a proprietary protocol which the SIMATIC components use to synchronize their times with each other.
 
FAQs Link
Configuration of the SIMATIC S7-300 as time master or time slave for time-of-day synchronization via Industrial Ethernet 44049612
Configuration of the SIMATIC S7-400 as time master or time slave for time-of-day synchronization via Industrial Ethernet 18130164
Configuration of a PC station as time master or time slave for time-of-day synchronization via Industrial Ethernet 44045424
Time synchronization through PROFIBUS in the SIMATIC environment 17544115
Time synchronization through PROFIBUS in the SIMATIC environment 17521938
How can you synchronize CPU clocks with each other? 24658964
How can you set the time of an S7-300 controller from WinCC if SIMATIC powerrate and a "Named Connection" are being used? 67852262
What are the options if the time synchronization does not function in the PLC as time slave? 25702851
Why does the message "Time jump noticed – switched to permanent slave mode" appear? 24039420
Do time synchronization with other modules or CPU stations from an S7 CPU (SFC48) 1292197
Why can you not use the IEEE Standard 1588 for synchronizing SIMATIC controllers? 22144689
     

Time synchronization with the NTP procedure

The NTP (Network Time Protocol) procedure is a standard for reliable timing in networks.
 
FAQs Link
Which SIMATIC S7-300/S7-400 modules support the NTP time-of-day message? 17990844
How do you configure a PC as NTP server? 22144502
Time synchronization using the NTP procedure (without SICLOCK) for small PCS 7 plants 61931975
Configuration of time synchronization in Windows domains 16620294
Why does the time interrupt start too late in SIMATIC PCS 7 during summer time? 17858505
     
Sample Applications Link
Time synchronization between an HMI operator panel and a SIMATIC PLC 69864408
Time synchronization between WinCC Runtime Professional and a SIMATIC PLC 67518641
Library for SNTP server functionality in S7-CPUs 82203451
Secure remote access to SIMATIC stations via Internet and UMTS 24960449
     

Time synchronization in SINAUT ST7 systems

In SINAUT ST7 systems you can use DCF77 radio receivers or NTP servers for time synchronization.
 
FAQs Link
Configuration of time synchronization in a SINAUT network 23810539
What should you watch out for when the time on TIM modules is set with an integrated DCF77 radio clock receiver? 51563241
What remedy is available if the time of day on an ST7cc PC or ST7sc PC is not automatically set by the TIM with DCF77 receiver which is connected to the MPI bus? 51558737

Time synchronization through a user program

Individual solutions for time synchronization through a user program.
 
FAQs Link
Time synchronization between SIMATIC T-CPU and SINAMICS S120 44356870
Time synchronization between SIMATIC T-CPU and SINAMICS S drive 60266999
Time synchronization between SIMATIC HMI Panel and SIMOTION CPU 23751257
Time synchronization between an operator panel with WinCC flexible and an S7-300/400 controller 24104104
How can you set the time of an S7 controller from WinCC? 7802886
How can you use the time of the GPS satellites in WinCC? 1069326
     
Sample Applications Link
Date and time synchronization with S7 Communication between multiple S7-1200 substations and an S7-1500/300 head end. 40556214
LCom communication library for Ethernet communication between SIMOTION and SIMATIC 48955385
Synchronization of the time of a Micromaster MM4 converter with a SIMATIC S7 CPU via PROFIBUS 25339612
Ethernet communication between S7-1200 and S7-200 40622389
SINAMICS S: Time synchronization between SIMATIC S7-CPU (STEP 7 V5) and SINAMICS 88231134
     

Time synchronization with HMI operator panels/PCS 7 systems

Below are entries concerning time synchronization with HMI devices and in PCS 7 systems.
 
FAQs Link
Configuration of time synchronization for WinCC clients (WinCC version < V6.0) 775131
Time synchronization between S5 and Windows-based operator panels 22008093
Time synchronization between TP170A / TP170micro / TP177micro and S7-200 CPU with WinCC flexible 19323674
Time synchronization between TP170A and S7-300 / S7-400 controller with WinCC flexible 24106357
Time synchronization between a line/graphics operator panel and an S7-300/400 with ProTool 24088798
Time synchronization between a line/graphics device and an S7-200 with ProTool 16807371
Time synchronization between an S7-300/400 and OP3 (C7-621) with ProTool 23972743
Time synchronization between a TP170A and an S7-300/400 controller with ProTool 23972509
Time synchronization between a Windows-based operator panel and an S7-300/400 controller with ProTool 24079457
Why are messages displayed in WinCC offset by one hour? 7604251
Time synchronization between a TP170A and an S7-200 CPU with ProTool 18630804
Why do messages coming from the PCS 7 PLC have a time stamp that is, for example, 2 hours ahead of time although the PCS 7 OS and the PLC are set to the same time? 17811102
Which settings need to be taken into consideration during time synchronization in PCS 7? 16622902
How do you set the date and time of WinCC via the Windows box? 268841
Configuration of time synchronization for WinCC clients (WinCC version < V6.0) 775131
What settings are to be made in Windows 7 in order to change the system time of the PC by means of WinCC flexible Runtime/WinCC Runtime Advanced? 59203176
     
Sample Applications Link
Time synchronization between an HMI operator panel and a SIMATIC PLC 69864408
Time synchronization between WinCC Runtime Professional and an S7 controller 67518641
SIMATIC PCS 7 – SIMATIC IT – Integration based on the PCS 7 / SIMATIC IT Integration Pack 2007 26639558
SIMATIC PCS 7 – SIMATIC IT – Integration based on the PCS 7 / SIMATIC IT Integration Pack V6.1 24639647

 

Products for time synchronization

Products and systems Link
Product description for SICLOCK Link
SICLOCK in Industry Online Support Link

Tools and general notes

Here you will find additional notes on handling the time-date types and other topics as well as a selection of manuals on the topic of time synchronization.
 
Function blocks Link
Which standard blocks of STEP 7 (V5.2 onwards) are available for time stamping and time-of-day synchronization? 15249609
How do you calculate the current local time in the S7-300/400 CPU and then use it as system time on the panel? 19324378
Reading out date and time with SFC1 (READ_CLK)  and writing date and time with SFC0 (SET_CLK)? 21222026
How do you convert an available seconds value into days, hours, minutes and seconds? 874721
Tips and tricks for reading and comparing date, time and counters 2443515
Which functions are available in STEP 7 V5.5 and in TIA Portal V11 for processing the data types DT and DTL? 63900229
In STEP 7 (TIA Portal), how can you input, read out and edit the date and time for S7-300/400/1200/1500? 43566349
How can you convert a time stamp (date and time) of the local computer time into coordinated world time (UTC)? 24201113
How can you use IEC functions to read and input the date and time of the CPU? 24658864
     
Further information about DCF77 Link
DCF 77 Receiver for WinCC 1046241
Download function blocks for SIPLUS DCF77 time receiver 56041890
Time synchronization with the DCF77 Time Receiver in PCS 7 V5.x 16533276
How is time synchronization configured with the DCF77 Time Receiver? 19693801
Why is the time not set by the software tool DCF77 Client? 17059590
     
Conferences in the Technical Forum Link
With the Technical Forum you have a discussion platform in German and English where users and experts can exchange experiences and know-how. German
English
   

How can you set the time of an S7 controller from WinCC?Go to beginning
Part number:

Description
The following solution is not time synchronization, but time setting. Therefore, this solution is not quite as precise as proper time synchronization, because message runtimes, C-script times etc. have to be calculated as delays.
Note also that time jumps (forwards/backwards) can occur, which means that the solution is not suitable for applications that must be chronologically correct.

The following solution writes the time with a WinCC script in static tags of a function block (FB1). These tags are also transferred to the system function "SET_CLK" (SFC0) when called as data type "Date_And_Time".

Additional Information

  • The settings to be made for time synchronization are given in Entry ID: 16622902.
  • How to configure time-of-day synchronization with Industrial Ethernet is described in Entry ID: 2416068.
  • How to configure time-of-day synchronization with PROFIBUS is described in Entry ID: 11932931.

Instructions
 
No. Procedure
1 Insert the system function SFC0 from the system library into the block container of your project.
  • For this you click "File > Open" and then select the "Libraries" tab.
  • Open the "Standard Library".


Fig. 01

The "System Function Blocks" folder contains the system function SFC0 (SET_CLK). Drag and drop this into the block container of your project.


Fig. 02

2 Create a function block (FB1 in the example) and create the tags in the order specified in the static area.
  1. Time Stamp as "Date_And_Time" (time for the SFC0)
  2. ret_value as "Int" (return value of the SFC0)
  3. Flag as "Bool" (WinCC trigger)


Fig. 03

3

Create a new network in FB1 and copy the STL code from the following file into that network:

   AWL-Code.txt ( 203 bytes )

Function

  • The time is only set when the C script is called in WinCC, which sets the trigger tag.
  • After setting the clock with "SET_CLK" the trigger tag is reset.
4
  • Call the created function block FB1 in OB1.
  • Select DB1 as the instance data block.
5 Start WinCC and in the Tag Management create the tags of the following table as "Unsigned 8-bit value" and under "Adapt format" you select "ByteToBCDByte".

Note
 The "Flag" tag is created as "Binary tag" and does not have any "Adapt format" value.


Fig. 04


Fig. 05

6 Open the Global Script C editor and create a new project function "File > New Project Function".
7
  • Delete the function template.
  • Insert the C script from the following file
  • Save the function

  C-Script.txt ( 634 bytes )

Note
The script currently works with the "Set System Time" function to write Greenwich Mean Time to the controller.
If you want to write the local time to the controller, you comment out the "Set System Time" function in the C script and replace it with the "Set Local Time" function (the relevant line is already commented out in the C script).

8

Call the function in a cyclic action or with a button.
Table 01

Additional Keywords
Time alignment, Time setting, GMP, Pharma, Life Science, Validation, FDA 21 CFR Part 11

Which functions are available in STEP 7 V5.5 and in TIA Portal for processing the data types DT and DTL?Go to beginning
Part number:

Description
In order to extract the values for year, month, day and time from the "DATE_AND_TIME" data type and process them you need different instructions or functions in STEP 7 (TIA Portal) and STEP 7 V5.5. In STEP 7 (TIA Portal), these instructions are in the "Advanced Instructions" palette, in the "Date and Time" folder. In STEP 7 V5.5 you need the IEC standard functions that are in the "Standard Library" of STEP 7.


Fig. 01

Fig. 01 shows the different functions you require to extract the data formats (TOD, DATE, INT, DINT and TIME) from the DT and DTL data types. The table below gives an overview of the functions for the different versions of STEP 7 and the CPU modules.
 
STEP 7 (TIA Portal) STEP 7 V5.5 Description
S7-300/400 S7-1200/1500 S7-300/400
WR_SYS_T WR_SYS_T SFC 0 "SET_CLK" Set time
RD_SYS_T RD_SYS_T SFC 1 "READ_CLK" Read time
T_CONV T_CONV * FC 6 DT_DATE Convert and extract times
FC 7 DT_DAY Convert and extract times
FC 8  DT_TOD Convert and extract times
T_COMBINE T_COMBINE FC3 D_TOD_DT Combine times
T_COMP - T_COMP (only S7-1500) FC 9 "EQ_DT" Compare time tags
T_ADD T_ADD FC 1 "AD_DT_TM" Add times
T_SUB T_SUB FC 34 "SB_DT_DT" Subtract times
FC35 "SB_DT_TM" Subtract times
T_DIFF T_DIFF - Time difference
* With the S7-1200/1500 you have direct symbolic access to the structure components of the DTL tags.

Difference between the DT data type and the DTL data type:

  • The "DT" data type stores the data for date and time in the BCD format, which means in a length of 8 bytes.
  • A variable of the "DTL" data type has a length of 12 bytes and stores the data for date and time in a predefined structure.

If you declare a tag (in a data block, for example) with the DTL data type, you can access the separate structure components of the structured tag.


Fig. 02

More detailed information about the functions and parameterization is also available in the Online Help of the corresponding versions of STEP 7. To obtain the Online Help you mark the block and click the "F1" key.

Creation environment
The screens in this FAQ response were verified with STEP 7 V12+SP1.

Which STEP 7 standard blocks are available for time stamping and time-of-day synchronization?Go to beginning
Part number:

Description:
As of version 5.2, STEP 7 includes the miscellaneous blocks or blocks for time stamping and time-of-day synchronization in the standard libraries. The following table includes an overview of the blocks and their function:
 
No. Blocks in the program folder "Miscellaneous Blocks":
FB60 SET_SW
FB60 supports summer-time/winter-time changeover in CPUs that do not have time-of-day status. For this purpose, it sets the CPU clock to the current time and according to the changeover rules in the control DB.
FB61 SET_SW
FB61 supports summer-time/winter-time changeover in CPUs that do have time-of-day status. For this purpose, it sets the time-of-day status to the current time and according to the changeover rules in the control DB.
FB62 TIMESTMP
FB 62 transfers time-stamped messages of an IM153-2 in its instance DB. The data for further processing by the user program is available there.
FC60 LOC_TIME
FC60 reads the time-of-day status or the time-of-day of the CPU and calculates the local time from this. Therefore, it can only be used on CPUs with time-of-day status.
FC61 BT_LT
FC61 calculates the local time from the basic time given at the input.
FC62 LT_BT
FC62 calculates the basic time from the local time given at the input.
FC63 S_LTINT
FC63 sets the required time interrupt to the preset time. This time is given in local time.
UDT60 WS_RULES
Data type for the control DB. Certain information must be available in a data block that is evaluated by different blocks. You create this block as DB of type UDT60 and enter the values valid for your location (in local time).

Opening blocks in the SIMATIC Manager:
The Miscellaneous Blocks are contained in the Standard Library.

  1. Open the dialog "Open Project" with "File > Open ..." and select the "Libraries" tab.
  2. In the library window, select "Standard Library" and confirm with OK. The Standard Library is now opened in the SIMATIC Manager.
  3. Open the "Miscellaneous Blocks" folder and, under "Blocks", copy the blocks (by drag & drop) into the block folder of your STEP 7 project.

Calling blocks in the LAD/STL/FBD editor:
Proceed as follows to call and parameterize the described blocks in the LAD/STL/FBD editor:

  1. Switch on the overview window in the LAD/STL/FBD editor with "View > Overviews".
  2. In the overview window, open the folder "Libraries > Standard Library > Miscellaneous Blocks".
  3. Select the required block and hold down the mouse key to drag & drop it into the network of your STEP 7 program.
  4. Parameterize the inputs and outputs of the block.

You will find more information on the description, function, parameterizing and on the output values in the STEP 7 Online Help, by selecting the block with the cursor and pressing the F1 key.

How is the runtime of a terminal device (pump, for example) calculated?Go to beginning
Part number:

Instructions
You can use the system time of the CPU to calculate the runtime. The system time is a "time counter" that counts from 0 to a maximum of 2147483647 ms. If the maximum value is reached, the counting starts again at 0 (overflow). By calling the SFC 64 "TIME_TCK" you can read out the current system time via the output parameter "RET_VAL".


Fig. 01

In order to calculate the time period between two events (switch-on and switch-off of an end device, for example), you call the SFC 64 twice. The difference between the return values (data type: Time) is obtained from a DINT subtraction. This gives you the time period between the two block calls. The time grid and the related precision of the system time are as follows:

  • S7-300: 10 ms
  • S7-400: 1 ms

The system time is only affected by the operating states of the CPU, but is independent of the cycle time.

Sample program: FC1
When there is a positive edge at the input "I.0", SFC 64 "TIME_TCK" is called for the first time and the system time read is temporarily buffered. After the positive edge at the input "I.0", SFC 64 "TIME_TCK" is called for again and the second system time read is temporarily buffered. The difference between the two system times is calculated when there is a positive edge at the input "I1.2". The result and thus the time value is output at the "Out_Time" output.


Fig. 02

Note
You can use the example described with FC1 for device runtimes less than the maximum system time. The system time of a maximum of 2147483647 ms corresponds to a maximum runtime for an end device of 24 days + 20 hours + 31 minutes +23 seconds +647 milliseconds. If you are using an end device with a longer runtime, you must extend the STEP 7 program by checking the system time for multiple overflows.

Download
The attached download "STEP7_V55_Source_RunTime" contains the STL source for the blocks described above. Proceed as follows to incorporate the block in your STEP 7 project:

  1. Click the link for the download and extract the "STEP7_V55_Source_RunTime.AWL" file into a separate directory on your hard disk.
  2. Open the your STEP 7 project in the SIMATIC Manager and select the source folder.
  3. Import the STL source extracted in the SIMATIC Manager into the source folder of your STEP 7 project via "Import > External Source...".
  4. Mark the imported STL source in the source folder and right-click.
  5. Select the "Compile" function in the pop-up menu. When the STL source has been compiled, the FC1 is stored in your block folder.

STEP7_V55_Source_RunTime.zip ( 837 bytes )

Separate time meters are incorporated in the S7 CPUs for calculating longer runtimes. You can set, stop and read the time meters using the SFCs 2, 3 and 4. More information about this is available in the STEP 7 Online Help by marking the block in the SIMATIC Manager and pressing the "F1" key.

Creation environment
The table below lists the components that have been used to create this entry and verify the function described.
 
Software Version
STEP 7 V5.5
S7 PLCSIM V5.4+SP4

Keywords
Time measurement

What is the modified Julian date and how can you calculate it with STEP 7?Go to beginning
Part number:

Instructions:
The Julian date is a decimal, serial numbering of the date. The advantage of this format is the better computability of periods of time between two remote points in time (astronomy). Furthermore, the Julian date is linked to world time (GMT) such that for international production the point in time of the production of a part can be determined independently of time zones (e. g. car industry).
In contrast to the Julian date, with the Modified Julian Date (MJD) the day changes at 0:00 GMT and not at 12:00 GMT. Furthermore, the MJD is a smaller number and easier to handle.

You can find a very good description of the Julian and the Modified Julian Date under following link:

www.greier-greiner.at/hc/juldat.htm

Description of the Sample Program:

In the enclosed program - created with STEP 7 V5.3 - the time difference to GMT is given at the input of the FC1 in the data type TIME. In Germany that is e. g. plus 2 hours during summer time (MESZ) and plus an hour during winter time (MEZ). At output of the FC1 you receive the Modified Julian Date as a real value.

FC1 itself retrieves with SFC1 the CPU time and adjusts it with the difference to GMT. From this corrected value in data type Date_and_Time the date is extracted in data type DATE. In case of STEP 7 this data type contains the number of days since 01.01.1990 (01/01/1990). The days to this "starting day" are added and the fractioned part of the current point in time (hours, minutes, seconds) is appended to the floating point number. Because of this very large floating point number there is a resolution of ca. 5 min. Since the display of floating point values in the tag table consists of 6 digits, there is a resolution of ca. 15 min visible.

MJD.exe ( 68 KB )  

Tips and tricks for reading and comparing date, time and countersGo to beginning
Part number:

Description:
This entry contains tips and tricks for reading and comparing date, time and counters. The topics below are covered.

  1. Reading and converting the remaining time of a timer
  2. Comparing "Months" with the "DATE" data type
  3. Adding S5TIME data together
  4. Incorrect values from the counter program

The table below provides information and remedies for the above.
 
No. Tips and tricks for reading and comparing date, time and counters
1 Reading and converting the remaining time of a timer
The following STL program uses MD8 "T1_IEC_time" to determine the remaining time of a time with switch-on delay.
  • The BCD output of the timer is transferred to MW6 "T1_BCD".
  • The data type of this value is WORD and must be converted into the S5TIME data type.
  • Because the BCD value still contains the time base multiplicator of the timer, the value in MW6 "T1_BCD" is copied into MW12 "BCD_S5TIME".
  • Then the function FC33 "S5TI_TIME" from the "Standard Library/IEC Function Blocks" library is used to convert MW12 "BCD_S5TIME" into the "TIME" format.
  • The result is located in MD8 "T1_IEC_time".

Copy the "STEP7_V5_RestTime.zip" file into a separate directory and then start the file with a double-click. The STEP 7 V5.4 project is then extracted automatically with all the associated subdirectories. You can then use STEP 7 V5.4 to open and process the extracted project.

STEP7_V5_RestTime.zip ( 34 KB )  

2 Comparing "Months" with the "DATE" data type
The "DATE" data is displayed as an unsigned integer in days, where the first day is January 1, 1990. It is not possible to make a direct comparison of the "Month" data with this data type. This is why you must convert the data type to DATE_AND_TIME using the TIME_OF_DAY data type. The DATE_AND_TIME data type is saved in BCD format.


Fig. 01

Now you can make a simple BCD comparison of the "Month" information with a second variable.

3 Adding S5TIME data together
The data is stored in BCD format in the S5TIME data type. You cannot simply add this format. If you convert the time into the TIME data type, the data is stored as a decimal number. As a decimal number, you can process this data type with the arithmetic commands of SIMATIC S7.
  • You can use the block FC 33 (S5TI_TIM) for converting the S5TIME data type into the TIME data type. The FC 33 (S5TI_TIM) is available in the Standard Library under "IEC Function Blocks".
  • If you need the time as S5TIME data type in your program, you can use FC 40 (TIM_S5TI) to convert the date into the S5TIME data type. This block is also available in the Standard Library under "IEC Function Blocks".
  • You open the Standard Library with the " Open a project/library" button in the SIMATIC Manager. Here, you select the "Libraries" tab and select "Standard Library".

Fig. 02 shows the limits of the S5TIME and TIME data types. More information on the different data types is also available in the STEP 7 Online Help under "LAD/STL/FBD - Edit Blocks".


Fig. 02

Copy the "STEP7_V5_S5time_Addition.zip" file into a separate directory and then start the file with a double-click. The STEP 7 V5.4 project is then extracted automatically with all the associated subdirectories. You can then use STEP 7 V5.4 to open and process the extracted project.

STEP7_V5_S5time_Addition.zip ( 36 KB )  

4 Incorrect values from the counter program
To achieve the correct value in the counter program in the case of two counters connected one after the other, you should set a positive edge before each counter. Furthermore, you should conduct the result of the timer (output value) to a flag to save it.


Fig. 03

Creation environment
The pictures and downloads in this FAQ were created with STEP 7 version V5.4.

How do you convert an available seconds value into days, hours, minutes and seconds?Go to beginning
Part number:

Instructions:
The following STEP 7 program can be used to convert an available seconds value into days, hours, minutes and seconds and output the results accordingly.


Fig. 01

Table 01 shows the input and output parameters with the data types and value ranges of function block FB1. The seconds value is input via the input parameter "value" and output of the converted value is via the output parameters "days", "hours", "min", "sec", or with the parameter "CounterString" (format: day:hours:minutes:seconds).
 

Input parameter

Type

Description

Range

value

DINT

Input value that gives the time in seconds

-2147483648,..,
+2147483647

Output parameter 

Type Description Range

days

INT

Number of days calculated

-32768,...,+32767

hours

INT

Number of hours calculated

0,...,24

min

INT

Number of minutes calculated

0,...,60

sec

INT

Number of seconds calculated

0,...,60

CounterString

STRING

Formatted output of the time calculated
Example: 19:23:54:11 (dd:hh:mm:ss)

Maximum 99 days

Table 01: Description of parameters

The attached download contains an archived STEP 7 project with the STEP 7 program described above. Block FB1 containing German and English comments is called in OB1.
Copy the "Sec_Chan.zip" file into a separate directory and unpack the file. You can then use the SIMATIC Manager to open and process the extracted project.

Sec_Chan.zip ( 37 KB )

Information about the topic of "Editing date and time"Go to beginning
Part number:

Instructions:
There is information about the topic of "Editing date and time" available in the following manuals and sections.
 
Document

Version

Section Entry ID
Manual
"Programming with STEP 7 V5.5"
05/2010 04 Basics of Designing a Program Structure
18 Establishing an Online Connection and Making CPU Settings
45531107

How can you measure the time?Go to beginning
Part number:

Instructions:
In automation technology measuring time is a frequent application in controllers. There are various options for measuring time with SIMATIC. This entry includes a STEP 7 program with six example for measuring time.

  1. Example: Time measurement with Timer T1
  2. Example: Time measurement with the IEC timer SFB4 "TON"
  3. Example: Time measurement with the system functions SFC2 "SET_RTM", SFC3 "CTRL_RTM" and SFC4 "READ_RTM"
  4. Example: Time measurement with the system function SFC101 "RTM"
  5. Example: Time measurement with the system function SFC64 "TIME_TCK"
  6. Example: Time measurement with the system function SFC1 "READ_CLK"

Examples 1, 2, 3 and 4 are programmed directly in OB1 and examples 5 and 6 are called as S7-SCL programs (FB1 and FB2) in OB1. With the VAT_1 variables table you can control and monitor time measurement for all six examples. The markers M0.0 "START" and M0.1 "RESET" are used to start and reset the six sample programs.

The table below describes the six sample programs.
 
No. Examples of time measurement
1 Example 1: Time measurement with Timer T1
Use the marker M0.0 to start or stop the preset time. The time starts to run again each time you start the marker.


Fig. 01

If the preset time for T1 ("S5T#20s" with parameter TW) has expired, the marker M10.0 (output Q of timer T1) receives the True signal.


Fig. 02

2 Example 2: Time measurement with the IEC timer SFB4 "TON"
The SFB4 delays a rising edge by the time PT. The time PT is started with a rising flank at the input IN.


Fig. 03

In the VAT_1 variables table you can monitor the expired time (ET) until the setpoint value (parameter PT) is reached.


Fig. 04

3 Example 3: Time measurement with the system functions SFC2 "SET_RTM", SFC3 "CTRL_RTM" and SFC4 "READ_RTM"
The system functions SFC2 "SET_RTM", SFC3 "CTRL_RTM" and SFC4 "READ_RTM" make it possible to measure the time with a 16-bit runtime meter of the CPU.
  • SFC2 is used to set the runtime meter of the CPU to a preset value.
  • SFC3 is used to start and stop the runtime meter.
  • SFC4 is used to read the current runtime elapsed and the status ("stopped" or "counting") of the runtime meter.

The marker word MW106 is parameterized with the output CV of SFC4 and provides the number of operating hours as in Fig. 05.


Fig. 05

4 Example 4: Time measurement with the system function SFC101 "RTM"
With SFC101 "RTM" you can measure the time with a 32-bit runtime meter. The program for example 4 includes 5 networks (networks 6 to 10) in OB1 for controlling and evaluating SFC101.
  • Nw 6: Read current runtime elapsed and status of the meter
  • Nw 7: Set (to value specified at Parameter PV)
  • Nw 8: Start (with last meter reading)
  • Nw 9: Stop
  • Nw 10: Call and parameterization of SFC101.


Fig. 06

The starting, stopping and setting of a new value is done as described above with markers M0.0 and M0.1. The current value of the runtime meter is read via the parameter "CV" (MD110).


Fig. 07

5 Example 5: Time measurement with the system function SFC64 "TIME_TCK"
The function block FB1 contains an S7-SCL program for acquiring the system time of the CPU with SFC64 and for evaluating the time measurement. FB1 is called and parameterized in network 11 of OB1.


Fig. 08

The starting, stopping and resetting is done as described above with markers M0.0 and M0.1. Fig. 09 shows the evaluation of the three variables in DB1:

  • DB1.DBD 2: Display of time measured
  • DB1.DBX 6.0: Status display for reset (= True)
  • DB1.DBX 6.1: Status display for excess (= True), because the system time is a time counter that counts from 0 to 2147483647 ms.


Fig. 09

6 Example 6: Time measurement with the system function SFC1 "READ_CLK"
The function block FB2 contains an S7-SCL program for acquiring the time of the CPU with SFC1 and for evaluating the time measurement. FB2 is called and parameterized in network 12 of OB1.


Fig. 10

The starting, stopping and resetting is done as described above with markers M0.0 and M0.1. Fig. 11 shows the evaluation of the three variables in DB2:

  • DB2.DBD 2: Display of days counted
  • DB2.DBD 6: Display of time measured in hours, minutes, seconds and milliseconds
  • DB2.DBX 10.0: Status display for reset (= True)
  • DB2.DBX 10.1: Status display for excess (= True)
  • DB2.DBX 10.2: Status display for inconsistency (= True) when clock is reset.


Fig. 11

Note:
More information on the timers, system function blocks and system functions is available in the STEP 7 Online Help by marking the block and pressing the "F1" key.

The attached download "Time_rec" contains a STEP 7 project with the blocks described above. Copy the "Time_rec.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can use the SIMATIC Manager to open and process the extracted project.

Time_rec.zip ( 391 KB )

Runnability and test environment:
The example can be used on all the CPU types of SIMATIC S7-300, S7-400, C7 and WinAC. The following table lists the components that have been used to create this entry and verify the functions described.
 
Test environment Version
PC platform: Intel(R) Pentium(R) M processor 1.73GHz, 1.49GB RAM
PC operating system: Windows XP SP2
STEP 7: V5.4 SP1
S7-SCL: V5.3 SP1
S7-PLCSIM: V5.3 SP1

Keywords:
S7-SCL (Structured Control Language)

How do you program a timer that retains the time value at STOP and counts on starting at the stored value?Go to beginning
Part number:

Instructions:
The following STEP 7 project "P_FB115" contains the function block FB115 with a program for a timer that retains its value at STOP. When the timer is started again it counts on from the value stored at STOP (up to a previously defined value). Fig. 01 shows how the timer functions.


Fig. 01

FB115 is called in OB1 and parameterized as described in the table below.
 

Parameter

Type

Description

Tmr_no

TIMER

T(#) number of the timer used

Tbase:

INT

0 =.01 second time base
1 =.1 second time base
2 =1 second time base
3 =10 second time base
Other numbers are ignored and the last valid time base is set

Preset

INT

Length of the time to be counted 0-999

T_start

BOOL

Positive edge starts the timer, negative edge stops the timer

T_Reset

BOOL

Timer is reset to 0

Number

S5TIME

Counts the time from 0 to Preset

EN

BOOL

Indicates whether the timer is counting evenly or not

DN

BOOL

Indicates when the Preset has been reached

The attached download "P_FB115" contains the STEP 7 project with the blocks described above (FB115, instance DB115 and OB1). Copy the "P_FB115" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can use the SIMATIC Manager to open and process the extracted project.

P_FB115.zip ( 337 KB )

Runnability and test environment:
The example can be used on all the CPU types of SIMATIC S7-300, S7-400, C7 and WinAC. The following table lists the components that have been used to create this entry and verify the functions described.
 
Test environment Version
PC platform: Intel(R) Pentium(R) M processor 1.73GHz, 1.49GB RAM
PC operating system: Windows XP SP2
STEP 7: V5.4
Options package S7 PLCSIM: V5.3

How can you set the time of an S7-300 CPU via Industrial Ethernet and via MPI?Go to beginning
Part number:

Procedure
In this entry we deal with the following topics:

Setting the time of an S7-300 via Industrial Ethernet
You can set the time either with a CP343-1 IT or use a CP343-1, for example, for S7 communication or UDP communication. We recommend that you always use a CP343-1 IT as communications processor, because it sets the time of the CPU via the SIMATIC procedure or via the NTP (Network Time Protocol). If you do not have a CP343-1 IT, you need an S7-400 that as time master provides the time to the S7-300 via relevant block calls.

  • You can synchronize the time of the S7-400 with SICLOCK, for example.
  • The "PUT" blocks (S7 communication) or the AG_LSEND/AG_LRECV blocks (UDP communication) are called, for example.
No. Procedure
1 Example for setting the time in an S7-300 with S7 communication
Configure your module in NetPro with SICLOCK as time master.


Fig. 01

2 Create a data block with the "DATE_TIME" structure for reading the CPU basic time in the S7-400.


Fig. 02

3 Read out the basic time of the CPU using SFC1 ("READ_CLK"). Fig. 03 shows the function call with SFC1 "READ_CLK".


Fig. 03

4 Transfer the time into a target area of the S7-300 using SFB "PUT". A sample program for S7 communication is available in Entry ID: 1819293.
5 Set the time in the S7-300 with the values transferred. Fig. 04 shows the call with SFC0 "SET_CLK".


Fig. 04

6 Example for setting the time in an S7-300 with UDP communication
  1. Read out the CPU basic time in the S7-300 (as described under No. 3).
  2. Configure a connection for the UDP communication. Configuration instructions for UDP connections are available in the manual in Entry ID: 20983558.
  3. In the S7-300 you program the block AG-LRECV (FC60) and the block AG_LSEND (FC50) in S7-400. A detailed sample program is available in Entry ID: 18513371.
  4. Set the time in the S7-300 with the values transferred (as described under No. 5).

Note
The NTP (network time protocol) procedure is also supported by the integrated interfaces of the CPU. The Send/Receive distribution can be made with the integrated interface and with any other Industrial Ethernet CP.

Setting the integrated clock of an S7 CPU with the computer time via MPI
You can set the integrated clock of an S7 CPU from your computer or transfer the time of your PC to the S7 CPU if your S7 station is connected to your PC via MPI. The procedure is described in the table below.
 
No. Procedure
1 Open your project and select the station in which you wish to change the time.
2 Right-click on CPU and select "PLC > Set time..." in the pop-up menu.
3 In the "Set Time of Day" dialog that opens you can set the date and time for your module.


Fig. 05

4 Select "Apply" and the module receives the time from the PG/PC. Make sure that the "Take from PG/PC" option is selected.

Note
In the case of a module without integrated real-time clock, 00.00.00 is output as date and 00:00:00 as time. More information is also available in the Online Help of STEP 7.

How do you load the IEC standard functions FC3, FC6, FC7 and FC8 from the STEP 7 IEC library?Go to beginning
Part number:

Instructions:
The IEC standard functions FC3, FC6, FC7 and FC8 are in the "Standard Library" of STEP 7. The following instructions are for the following functions:

  1. Use the SIMATIC Manager to copy the functions into your STEP 7 project
  2. Use the LAD/FBD/STL editor to insert the functions into your selected network
No. Loading the IEC standard functions from the STEP 7 IEC library in the SIMATIC Manager
1 Open the dialog "Open Project" in the SIMATIC Manager with "File > Open ..." and select the "Libraries" tab.
2 As shown in Fig. 01 mark "Standard Library" with the cursor and then click the OK button. The Standard Library is now loaded into the SIMATIC Manager.


Fig. 01

3 As shown in Fig. 02 now open the "Blocks" folder under "IEC Function Blocks". Then you can copy functions FC3, FC6, FC7 and FC8 into your STEP 7 project (in the Blocks folder).


Fig. 02

 
No. Inserting the IEC standard functions from the STEP 7 IEC library in the LAD/FBD/STL editor
1 First open the "Views" window in the LAD/FBD/STL editor via "View > Overviews". Then the overview of the "Program Elements" and the "Call Structure" is displayed on the left.
2 As shown in Fig. 03 in the "Overviews" window you now open the "IEC Function Blocks" folder.


Fig. 03

3 Here you can now insert the functions described above in the LAD/FBD/STL editor:
  • In the STL editor:
    Place the cursor in the network on the program point where you would like to call the function. Then double-click the function you wish to insert in the STL editor (e.g. FC7). The block call (e.g. CALL "DT_DAY") is now executed automatically in the STL editor.
  • In the LAD/FBD editor:
    Here you can use drag-and-drop to insert the required block at the relevant point in the program.

Then you still have to parameterize the block inserted.

How can you use IEC functions to read and input the date and time of the CPU?Go to beginning
Part number:

Instructions:
The values for year, month, day, hour etc. can also be extracted from the format DATE_AND_TIME using the standard functions of the STEP 7 IEC library without using the address register.

  • FC 6    DT_DATE:
    Function FC 6 extracts the data format DATE (date 16 bits) from the format DATE_AND_TIME.
  • FC 7    DT_DAY:
    Function FC 7 extracts the day of week (integer) from the format DATE_AND_TIME.
  • FC 8    DT_TOD:
    Function FC 8 extracts the data format TIME_OF_DAY (time 32 bits) from the format DATE_AND_TIME.

In this way the elements of date and time are available in the usual format. You can then process this data as required.

The download attached contains an example for each of the IEC functions described.
In Network 1 the date and time are read with SFC1 and output in the data format DATE_AND_TIME. In Network 2 IEC functions FC6, FC7 and FC8 are used to extract the date, day of week and time from the format DATE_AND_TIME and save them in marker words MW6, MW8 and MD10. 
The following table gives an example of the output:
 
Operand Display format Status value
MW6 Date D#2003-05-15
MW8 Decimal 5 (for day of week)
MD10 Time T#14h20m17s654ms

Source_FC20.zip ( 681 bytes )

After downloading, unpack the source "Source_FC20" from the zip file and import the source into your STEP 7 project. Then load the IEC functions FC6, FC7 and FC8 from the Standard Library of STEP 7 and system function SFC1 into your project. Now you can compile the source "Source_FC20" and then edit FC20 in the LAD/FBD/STL editor. FC20 contains comments in German and English.

The values for date and time can also be combined into the format DATE_AND_TIME using a standard function from the STEP 7 IEC library without using the address register.

  • FC3  D_TOD_DT:
    Function FC3 combines the data formats DATE and TIME_OF_DAY and converts these formats into the data format DATE_AND_TIME.

Unpack the source "Source_FC21" from the zip file and import the source into your STEP 7 project. Then load the IEC function FC3 from the Standard Library of STEP 7 and system function SFC0 into your project. Now you can compile the source "Source_FC21" and then edit FC21 in the LAD/FBD/STL editor.

Source_FC21.zip ( 614 bytes )

FC21 contains comments in German and English. Via marker words MW0 and MD2 the data is copied into two temporary variables of the type DATE and TIME_OF_DAY and combined using the IEC function FC3. The output parameter "RET_VAL" of function FC3 outputs the date and time in the format DATE_AND_TIME. This value is stored temporarily in a temporary variable and loaded into the CPU using system function SFC0. The following table gives an example of the input.
 
Operand Display format Status value Modify value
MW0 Date D#2003-05-15 D#2003-05-15
MD2 Time of day TOD#14:20:00:000 TOD#14:20:00:000

Note:
Using the IEC standard function FC1 you can add a length of time (format "TIME") to the point in time (format "DT"). As a result you obtain a new point in time (format: "DT"). The point in time must be in the range from DT#1990-01-01-00:00:00.000 to DT#2089-12-31-23:59:59.999. It is not possible to add more than 24 hours.

How can you synchronize CPU clocks with each other?Go to beginning
Part number:

Instructions:
If multiple CPUs are linked with each other in a subnetwork, you parameterize the clock of one CPU as the master clock. When parameterizing the CPU you also specify the synchronization interval after which all the clocks in the subnetwork are automatically synchronized with the master clock. You call system function SFC48 "SNC_RTCB" in the CPU with the master CPU. The call synchronizes all the clocks in the subnetwork regardless of the automatic synchronization. If you set a master clock with SFC0 "SET_CLK", all the other clocks in the subnetwork are automatically synchronized with that value.
 
No. Description
1 Open the Hardware Configuration in the CPU that you wish to parameterize as master CPU and open the Properties of that CPU.
2

In the Properties of the CPU you select the "Diagnostics/Clock" tab and set the type of Synchronization Mode and Time Interval as shown in Fig. 01. Then save with OK.


Fig. 01

3 Then save and compile the hardware configuration with "File > Save and Compile".

Note:
Repeat Steps 1 to 3 for all other CPU modules to be synchronized. However, for these groups you must set the type of synchronization to "As Slave".

4 Then open the dialog "Open Project" with "File > Open ..." and select the "Libraries" tab. As shown in Fig. 02 mark "Standard Library" with the cursor and then click the OK button.


Fig. 02

5 The Standard Library is now loaded into the SIMATIC Manager. Under "System Function Blocks" (Fig. 03) you will find the system functions. Copy system functions SFC0 and SFC48 by drag-and-drop to the block folder of your master CPU.


Fig. 03

6 How to set the date and time using system function SFC0 is described in the FAQ with Entry-ID 21222026.
More information on parameterizing SFC0 and SFC48 is also available in the Online Help of STEP 7 (F1 key). After loading both system functions into the CPU (master clock) all the other clocks in this subnetwork are automatically synchronized.

How can you count forwards and backwards in a bandwidth between -2147483648 and +2147483647?Go to beginning
Part number:

Instructions:
The attached download "D_Count" performs counting forwards and backwards in a bandwidth between -2147483648 and +2147483647 by an edge change at the "UP" and "DOWN" inputs. An edge change at the "L_PRESET" input transfers a value preset at the "PRESET" parameter to the "COUNT" output. The forwards and backwards counting via the parameters "UP" and "DOWN" increments/decrements the value at the "COUNT" output accordingly by "1". If during counting the "COUNT" output reaches a value that is equal to or greater than the value entered at the "COMPARE" input, "Q_COMPARE" output receives the signal "1".


Fig. 01

Sample application:
Boxes are transported from A to B on a conveyor belt.

  • Scan 1 detects the boxes placed on the conveyor and with the input E0.0 the value at the "Count" output is incremented by "1".
  • Scan 2 detects the boxes removed from the conveyor and with the input E0.1 the value at the "Count" output is decremented by "1".
  • If boxes are removed or sorted out during the course of the transport and are not detected by Scan 2, then the value at the "COUNT" output increases due to the difference by "1" for each box removed. In the example a value of 20 boxes is preset at the "COMPARE" parameter (Fig. 01). If the "COUNT" output reaches the value 20 (difference value of the boxes removed or lost), the output A0.0 receives the signal "1".

Through a plug-in (not included in the download FB100), you can program stopping of the conveyor belt with reference to the signal at output A0.0.


Fig. 02

The table below describes how to program the function block FB100 shown in Fig. 01.
 
No. Description of program in FB100
1

Network 1:
A positive edge at the input "UP" (type: BOOL) increments the static variable "S_COUNT" (type: DINT) so that counting goes forwards by "1" at every edge change here.

  • L  #S_COUNT
  • L  L#1
  • +D
  • T  #S_COUNT
2

Network 2:
A positive edge at the input "DOWN" (type: BOOL) decrements the static variable "S_COUNT" (type: DINT) so that counting goes backwards by "1" at every edge change here.

  • L  #S_COUNT
  • L  L#1
  • -D
  • T  #S_COUNT
3 Network 3:
A positive edge at the input "L_PRESET" (type: BOOL)  transfers the preset value between the input "PRESET" (type: DINT) and the static variable "S_COUNT".
4 Network 4:
The value of the static variable "S_COUNT" actually calculated from Networks 1, 2 or 3 is transferred to the output "COUNT" (type: DINT).
5 Network 5:
Here there is query as to whether the value at the output "COUNT" is greater or equal to the comparison value entered at the input "COMPARE" (type: DINT). In this case the output "Q_COMPARE" (type: BOOL) receives the signal "1".
  • L  #S_COUNT
  • L  #COMPARE
  • >=D
  • =  #Q_COMPARE
6 Network 6:
The RLO (result of logic operation) is set to "True" with the statements "SET" and "SAVE" and saved in the BR bit.

FB100 is called with its instance DB DB100 in OB1.

Note:
A normal STL program can only count to 65535 if you use "+ 1" to increment in the STL program. The "+ 1" command causes the compiler to execute a 16-bit operation. You can use the "+ L#1" command to make the compiler execute a 32-bit operation when incrementing. This command enables the program to count to 2147483647.

The attached download "D_Count" contains a STEP 7 project with the blocks described above (FB100, instance DB100 and OB1).

d_count.zip ( 228 KB )

Copy the "D_Count" file into a separate directory and then start the file with a double-click. The STEP 7 V5.3 project then unpacks automatically with all the associated subdirectories. You can then use the SIMATIC Manager to open and process the extracted project.

Runnability and test environment
The example can be used on all the CPU types of SIMATIC S7-300, S7-400, C7 and WinAC. The following table lists the components that have been used to create this entry and verify the functions described.
 
Test environment Version
PC platform Pentium(R) CPU 2.40 GHz
PC operating system Windows XP SP2
STEP 7 V5.3 SP3
Options package S7 PLCSIM V5.3

These instructions have been created with STEP 7 V5.3.

How can you read out the date and time with SFC1 (READ_CLK) and input them with SFC0 (SET_CLK)?Go to beginning
Part number:

Instructions for reading out the date and time with SFC1 (READ_CLK)
With system function SFC1 (READ_CLK) you read out the time in the CPU. At the output parameter "CDT" of system function SFC1 you receive the date and time in the format "DATE_AND_TIME". With the data type "DATE_AND_TIME" the date and time are stored in the BCD format in 8 bytes. This data type covers the range:

  • DT#1990-1-1-0:0:0.0 to DT#2089-12-31-23:59:59.999

The table below gives the example of Thursday, August 5, 04, 08:05 hours and 5.25 seconds. The table shows the contents of the bytes that contain date and time data.
 
Byte Contents Example
0 Year B#16#04
1 Month B#16#08
2 Day B#16#05
3 Hour B#16#08
4 Minute B#16#05
5 Second B#16#05
6 The two highest value digits of MSEC B#16#25
7 (4 MSB) The two lowest value digits of MSEC B#16#0
7 (4 LSB) Day of week:
1: Sunday, 
2: Monday, 
3: Tuesday, 
4: Wednesday, 
5: Thursday, 
6: Friday, 
7: Saturday
B#16#5

More information on the data type "DATE_AND_TIME" is also available in the Online Help of STEP 7, under: 

  • Format of data type DATE_AND_TIME

The reading of date and time via the address register AR1 is programmed in the following STEP 7 program (Fig. 01). FC1 reads the current time of the CPU using the system function SFC1. The hours and minutes are displayed on the digital display.


Fig. 01

With the statement:

    "LAR1  P##Date_Time

the address of the temporary variable "Date_Time" is loaded into the address register AR1. Access to the separate bytes for year, month, day, hour etc. is via indirect load commands.
Example:

    "L  B[AR1, P#3.0] //Read hours". 

This data is then output for display at the output bytes, e.g.

    T  "Hour"  // for QB3.

Because of the overlapping in Byte 7 with the 4 "Most Significant Bits" (MSB) for milliseconds and the 4 "Last Significant Bits" (LSB) for day of week, for display reasons the relevant values in AW6 and AB8 are hidden using the statements "L  W#16#FFF0" and "L  B#16#F" respectively and the corresponding AND links "UW". Otherwise digit 3 (for day of week 3) would stand for the last tetrad in AW6 and digit 5 (for milliseconds) for the first tetrad in AB8.

In "Monitor/modify variable" you can output the data of the output byte. Fig. 02 shows the example of Tuesday, August 3, 04, 8:03 hours.


Fig. 02

Instructions for inputting the date and time with SFC0 (SET_CLK)
With SFC0 "SET_CLK" (set system clock) you can set the date and time in a CPU. The CPU clock then runs as of this time and date set. With the statement:

    "LAR1  P##Date_Time

the address of the temporary variable "Date_Time" is loaded into the address register AR1. The data is loaded and transferred from the IN variables of the function (type: byte) via indirect addressing to the separate bytes for year, month, day, hour etc. of the variable "DATE_AND_TIME".
Example:

L  #Year
//IN variable, type: Byte
//Input for the variable "year" e.g. "B#16#05" for 2005.

T  B[AR1,P#0.0] 
//Content of the IN variable "Year" is transferred to Byte 0
//of the variable "DATE_AND_TIME".

In the example described above you see the format of the data type "DATE_AND_TIME". More information on the data type "DATE_AND_TIME" is also available in the Online Help of STEP 7, under: 

  • Format of data type DATE_AND_TIME

With the subsequent call of SFC0 and parameterization with the temp variable "Date_Time" at the input "PDT" the data is transferred to SFC0.


Fig. 03

In "Monitor/modify variable" you can specify the values for the date and time. The inputs for year, month, day, ... are parameterized in OB1 with the marker bytes MB0, MB1, MB2, ... . Fig. 04 gives the example of wednesday, August 4, 04, 9:05 hours.


Fig. 04

 

How can you create a timer for the "S7" without using an "S7 Timer"?Go to beginning
Part number:

Instructions:
The "S7 CPUs" have a time cell (TIMETICK) that counts cyclically in [ms] from 0x0 to 0x7FFFFFFF. The "S7-400 CPUs" and "CPU 318" do this in "ms resolution" and very accurately. The other "S7-300 CPUs" (except CPU 318) count in 10ms resolution.
The "TIMETICK" is also in "WinAC" Basic (SoftPLC) and counts in 10ms resolution.
The following concept is based on the "SFC64"(TIMETICK), which reads out the current "TIMETICK" of the "CPU". This makes it possible to create as many timers as you want without using up the "TIMER resources" of the "CPU".

The principle of timing generation is simple. If timing is to be started, the current "TIMETICK" is read from the "CPU" and stored. If the timer is to be queried at a later time, you need a function that calculates the time that has passed since the timer was started.
Based on this simple functionality you can create as complex pulse and time functions as you want.

A cycle-based timing suffices in many applications; in fact it is often demanded for the sake of consistency. The concept takes this demand into account, but it is also suitable for call-based timing in the ms range.

Advantages of this concept:

  • Optimum for runtime.
  • The "TIMER" system resource is not used.
  • Scalable accuracy (cycle-based as in the example, or call-based if "SFC64" is called when the time is started and queried).
  • Application makes memory resources (DW) available for the FC, which makes it possible to have as many timers as you want.

Infrastructure for the cycle-based TIMER

The basis for timing generation is the "TIMETICK" of the "CPU". For cycle-based timing, it is sufficient to read the "TIMETICK" once per cycle, save it and make it accessible to all applications (FB, FC). Central, cyclic readout saves cycle time. The "SFC64" doesn't have to be called for each timer in each cycle.

A sample application for "TIMETICK" is available in Entry ID 8736822.

Note:
All S7-300 CPU modules from firmware V2.4 onwards have a granularity of 1ms.

Keywords:
Timer, Resources

 Entry ID:22818923   Date:2014-04-02 
I regard this article....as helpfulas not helpful                                 






























mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Topics
Help
Online Help
Guided Tour