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"?
How can you measure the time?
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)

 Entry ID:26116927   Date:2007-08-03 
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