×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 2443515, Entry date: 07/12/2010
(5)
Rate

Tips and tricks for reading and comparing date, time and counters

  • Entry
  • Associated product(s)

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.

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.