How to convert the system clock to INT data type

able lee

Member
Join Date
Jun 2006
Location
china
Posts
18
HI, my friends:
i have some question. in the simense PCS7, i want to read the current system clock and convert it to the INT or WORD data type so as to read in the SCADA 。 but i have no idea of that 。some engineer advice me to use FC90 ,but i do not think it is a good way .any one have some good suggestion ?
thanks advance




able lee
 
thanks for you reply
i can get the system clock which is comprised from BCD
but i want convert it to INT type .
how can i read the example for data convertion?

thanks
 
I've not used a SCADA system, but can't you do the conversion from BCD to integer in the SCADA ?

If not, then the date is packed in bytes as follows:

Year
Month
Day
Hour
Minute
Second
milliseconds (this is a word).

You will need to declare an integer area for the converted data and then just go through them one by one using the BTI instruction

e.g.
L DB1.DBB0 (assume the year is stored here in BCD)
BTI
T DB2.DBW0 (assume year is stored here in integer)
 
SimonGoldsworthy :

you give me a good solution.


e.g.
L DB1.DBB0 (assume the year is stored here in BCD)
BTI
T DB2.DBW0 (assume year is stored here in integer)

the date is packed in bytes ,and follow:

Year
Month
Day
Hour
Minute
Second
milliseconds (this is a word).


but in DB1 ,You should declare it in data_time.

my question is how to divide the packed data and get my required data like year ,month ,day etc?

thanks
 
The DATE_TIME format is 8 bytes long. Its already divided within the 8 bytes.


For example if you have created the DATE_TIME variable in the DB starting at DBB6, then

DBB6=Year
DBB7=Month
DBB8=Day
etc..

Therefore as Simon said use the BTI on each byte

For day in the above example

L DBB8
BTI

etc
 
You could use the following FC which will extract the date and time information and return the values as integers - you can then put them where you want.


Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_OUTPUT
  iYear : INT ; 
  iMonth : INT ; 
  iDay : INT ; 
  iHour : INT ; 
  iMinute : INT ; 
  iSecond : INT ; 
  iMilliSecond : INT ; 
END_VAR
VAR_TEMP
  datetime : DATE_AND_TIME ; 
  sfc1_return : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =Read system time to temp
	  CALL sfc1 (
		   RET_VAL				  := #sfc1_return,
		   CDT					  := #datetime);
NETWORK
TITLE =address register to poin to local date and time
	  LAR1  P##datetime; 
NETWORK
TITLE =year
	  L	 B [AR1,P#0.0]; 
	  BTI   ; 
	  T	 #iYear; 
NETWORK
TITLE =month
	  L	 B [AR1,P#1.0]; 
	  BTI   ; 
	  T	 #iMonth; 
NETWORK
TITLE =day
	  L	 B [AR1,P#2.0]; 
	  BTI   ; 
	  T	 #iDay; 
NETWORK
TITLE =hour
	  L	 B [AR1,P#3.0]; 
	  BTI   ; 
	  T	 #iHour; 
NETWORK
TITLE =hour
	  L	 B [AR1,P#4.0]; 
	  BTI   ; 
	  T	 #iMinute; 
NETWORK
TITLE =hour
	  L	 B [AR1,P#5.0]; 
	  BTI   ; 
	  T	 #iSecond; 
NETWORK
TITLE =millisecs
	  L	 B [AR1,P#6.0]; 
	  BTI   ; 
	  T	 #iMilliSecond; 
END_FUNCTION
 
Simon

I'm nowhere that I can check at the moment, but I seem to remember that the last two bytes are not millisecs. One of the bytes is tenths and hundredths (not milli) and the final byte is the day-of-week (1-7).

Can you check and confirm?

regards

Ken
 
The format is as below (hope the cut and paste is good) no it wasnt

BYTE - MEANING
0 - Year
1 - Month
2 - Day
3 - Hour
4 - Minute
5 - Second
6 - Two most significant digits of MSEC
7 - Least significant digits of MSEC (4 MSB)
7 - Day of week(4 LSB) where:

1=Sunday to 7=Saturday
 
Last edited:
Ken/Peter - Thanks for pointing out my error. I ran this code in the simulator and saw that the millisecs were changing. I didn't know about the day of the week coding. - if able lee needs the millisecs then it shouldn't be too tricky to correct the posted code.
 

Similar Topics

Greetings fellow PLC programmers, I know there is a simple way to get the system date time of the RSLogix system. But, is there then a way to...
Replies
12
Views
8,649
Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
107
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
344
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,446
Hello, could someone kindly convert the attached RSP files that are currently used for SLC 5 PLC into PDF please
Replies
6
Views
550
Back
Top Bottom