S7-300 Set PLC Clock

Mushu

Member
Join Date
Nov 2005
Location
Cork
Posts
7
Hi,

I need to syncronize the PLC date andtime with the SCADA date and Time.

I will get 6 integers (my Set Points) and I have to set the PLC clock.

I know how to check if a syncronization is needed. But I don't know how to get the Date_and_Time data type needed for the SFC0 (SET_CLK)

o_O

Thanks
 
From the help-index of Siemens


Date and Time

You enter the date and time as data type DT. As an example: for January 15th, 1995, 10:30 a.m. and 30 seconds you would enter: DT#1995-01-15-10:30:30. The time can only be entered with a precision of seconds. The day of the week is calculated by SFC 0 "SET_CLK" from the date.

Remember that you must first create the data type DT with the FC "D_TOD_DT" before you can transfer input parameters to it (see time functions; FC 3, FC 6, FC 7, FC 8, FC 33, FC 40, FC 1, FC 35, FC, FC 34).
 
Last edited:
Thank you. :D

But how can generate the inputs for D_TOD_DT? I need a DATE (number of days from 1st January 1990) and a TIME_OF_DAY (miliseconds from midnight).

How can I generate those two inputs from 6 integers (year, month, day, hour, minute and second)? :confused:

Thank again!!
 
The DATE_AND_TIME data type is effectively a structure containing 8 BCD values in a specific order. You can't access the subelements directly using a UDT reference, however (DateAndTime.Hour is not a valid reference). This is from the Siemens online help about the DATE_AND_TIME data type:


Code:
The following table shows the contents of the bytes that contain the date and time information for the example Thursday, December 25, 1993, at 8:01 and 1.23 seconds in the morning. 




[b]Byte 
[/b][b]Contents 
[/b][b]Example 
[/b]0 
Year 
B#16#93 
[list=1]
[*]
[/list][list=1]
[/list]Month 
B#16#12 
[list=1]
[*]
[/list][list=1]
[/list]Day 
B#16#25 
[list=1]
[*]
[/list][list=1]
[/list]Hour 
B#16#08 
[list=1]
[*]
[/list][list=1]
[/list]Minute 
B#16#01 
[list=1]
[*]
[/list][list=1]
[/list]Second 
B#16#01 
[list=1]
[*]
[/list][list=1]
[/list]Two most significant digits of MSEC 
B#16#23 
[list=1]
[*]
(4MSB)
[/list][list=1]
[/list]Two least significant digits of MSEC 

B#16#0 
7 
(4LSB) 
Day of week 
1 = Sunday 
2 = Monday 
... 
7 = Saturday 
B#16#5

So create a DATE_AND_TIME data type in one of your global DBs. Then operate on each element directly. Remember that the values are BDC so if you are receiving the datae and time values in any other format you will need to converet them to BCD before putting them in the appropriate spot. The bnice thing about sticking with the DATE_AND_TIME format is it is a format the the S7 can operate on.

Keith
 
Format of the Data Type DATE_AND_TIME



When you enter date and time using the DATE_AND_TIME data type (DT), your entries are stored in binary coded decimal format in 8 bytes. The DATE_AND_TIME data type has the following range:



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



The following examples show the syntax for the date and time for Thursday, December 25, 1993, at 8:01 and 1.23 seconds in the morning. The following two formats are possible:



  • DATE_AND_TIME#1993–12–25–8:01:1.23
  • DT#1993-12-25-8:01:1.23
The following special IEC (International Electrotechnical Commission) standard functions are available for working with the DATE_AND_TIME data type:



  • Convert date and time of day to the DATE_AND_TIME format
FC3: D_TOD_DT



  • Extract the date from the DATE_AND_TIME format
FC6: DT_DATE



  • Extract the day of the week from the DATE_AND_TIME format
FC7: DT_DAY



  • Extract the time of day from the DATE_AND_TIME format
FC8: DT_TOD
 
I don't have any problem reading the PLC date and time and compare with integers set points; so I know if a sequence has to start or not base on date and time.

The problem is that I need to syncronize my PLC with my SCADA date and time. I am receiving 6 set points (year, month, day, hour, minute and seconds) if the difference is bigger than a minute, I have to syncronize my PLC time.

I know how to get from a DATE_AND_TIME variable, the year, the month, the day, the hour, the minute and the second, in Integers.

But I don't know how to convert my six setpoint into a DATE_AND_TIME variable.
 
You want to create an FC that will output a DATE_AND_TIME.

Then you will need to convert your Integers and Double Integers to BCD format. As you convert them, transfer them to the local byte or word (LB or LW) as necessary to get the DT output.

EX:
L MB20 //This is your year integer
ITB //Convert integer to BCD
T LB0 //This is Local Byte that corresponds to the year for your DT output.
 
I thought I understood what you needed but now I don't think I do. In you last post you seem to indicate that you understand that the DATE_AND_TIME data type is just an 8-element array of BCD values. You seem to say that you know how to read each element in the array so you can do comparisons on them. If you can read an element of the group you can write it.


Let's say you get your PLC time using SFC1 and stick it in DB20.DBX0.0, which you already defined as a DATE_AND_TIME data type. you now have a group of 8 BCD numbers that represent the PLC time and date. You can now write whatever numbers you want into the individual bytes in DB20. Just make sure the values are in BCD format before you write them. So if you need to update the year, write the year into DB20.DBB0. If you want to update the hour, write the desired number into DB20.DBB3. Once you have everyting updated that you need, use SFC0 to write DB20.DBX0.0 back to the PLC.

I hope this is what you are looking for.
Keith
 
Hello!

This is my code to set the plc clock from WinCC:

Code:
// Convert WinCC time data from int to bcd
      L     #WinCC_CommonData_In.DateTime.ServerTime.Year
      ITB   
      T     #TimeConversion.Year
      L     #WinCC_CommonData_In.DateTime.ServerTime.Month
      ITB   
      T     #TimeConversion.Month
      L     #WinCC_CommonData_In.DateTime.ServerTime.Day
      ITB   
      T     #TimeConversion.Day
      L     #WinCC_CommonData_In.DateTime.ServerTime.Hour
      ITB   
      T     #TimeConversion.Hour
      L     #WinCC_CommonData_In.DateTime.ServerTime.Minute
      ITB   
      T     #TimeConversion.Minute
      L     #WinCC_CommonData_In.DateTime.ServerTime.Seconds
      ITB   
      T     #TimeConversion.Seconds
      L     0
      T     #TimeConversion.MS_LS
      T     #TimeConversion.MS_MS

      CALL  "FILL"
       BVAL   :=#TimeConversion
       RET_VAL:=#RetVal
       BLK    :=#TempTime               // Date and time variable
      CALL  "SET_CLK"
       PDT    :=#TempTime               // Date and time variable
       RET_VAL:=#RetVal

TimeConversion is a struct with the same structure as a Date and time variable. It's just to make it a bit more "readable".

Cheers
Borte
 
Thank you to everybody.

I see that I didn't need the day of the week. The function is working perfetly.:p

Thanks again
 

Similar Topics

Hi I am running a CCW application to control a K300 servo drive. Most of it works with the exception of being able to change the motor direction...
Replies
1
Views
1,625
Dear All, i want to know how we Date and Time set and Change from HMI MP277 use Wincc Flexible.PLC is S7 300 CPU 315 2-DP.i use SFC0,SFC1 but...
Replies
4
Views
5,720
Hi all, Right now I am on Commisioning in Vietnam and I need urgent help with resetting PLC password. I have got safety PLC S7 300, CPU 315F-2...
Replies
12
Views
41,285
I apologize if this has been covered here before, but I am curious if it is possible to set a PLC system time to the system time in the PC which I...
Replies
1
Views
7,445
Hello everybody! I am working on upgrading an exisiting PLC system comprising of a Symax Model 300 PLC. I am replacing it with an Allen-Bradley...
Replies
10
Views
6,229
Back
Top Bottom