S7 300 PLC real time clock time

pauly

Member
Join Date
May 2002
Location
South Wales,U.k
Posts
244
Further to a post yesterday regarding access to the PLC's real time clock in an S7 300 PLC, I have followed the advice of the forum and used the SFC1 and put the results into A vat table. The time of day comes back, but in a HEX BYTE as per the picture attached. How can I convert this number to an integer for example for use in a comparison with an HMI operator entered value?
 
Use the BTI instruction to convert each entry from BCD to integer. Do you need the millisecs and day of the week ?
 
Here is code provided by user GeneInc from december 2009; it uses the BTI instruction in STL:


Here is my code. This takes the current date and tme and puts it into individual integers. You can create a FC with this (hence the # before the variable) or just make it a rung in your program.

CALL SFC 1 //Get Date and Time
RET_VAL:=#RetVal
OUT0 :=#Out_Time_Date //Date and Time

//Extract Year
L LB 2 //Load Byte 2
BTI //Convert To Integer
T #int_Year //Store in Variable
//Extract Month
L LB 3
BTI //Convert To Integer
T #int_Month
//Extract Day
L LB 4
BTI //Convert To Integer
T #int_Day
//Extract Hour
L LB 5
BTI //Convert To Integer
T #int_Hour
//Extract Minute
L LB 6
BTI //Convert To Integer
T #int_Minute
//Extract Second
L LB 7
BTI //Convert To Integer
T #int_Second

Hope this helps,
Daniel Chartier
 
Reviving thread as I'm having trouble using the real time clock. I'm trying to keep a runtime count of a process and reset this every 6AM and 6PM. Here is my code (took from another thread):

CALL "READ_CLK" //Call SFC 1, "Read System Clock"
RET_VAL:=#Return
CDT :=#ReadCurrentTime


//***************************
//Load each byte of #ReadCurrentTime and transfer
//them to data bytes. This wouldn't be
//absolutely necessary, but it's nice to go online
//with the block and see what the current time is.
//Use the Siemens Help to see the "Date and Time"
//format to see why I have to SLW12 and SRW12 on LB7.
//***************************
L LB 0
T "Daily Reset DB".Year
L LB 1
T "Daily Reset DB".Month
L LB 2
T "Daily Reset DB".Day
L LB 3
T "Daily Reset DB".Hour
L LB 4
T "Daily Reset DB".Minute
L LB 5
T "Daily Reset DB".Second
L LB 6
T "Daily Reset DB".MillisecMSB
L LB 7
SLW 12
SRW 12
T "Daily Reset DB".DayofWeek


//***************************
//Siemens uses the BCD format in the Date And Time,
//so I have to use the BTI instruction to convert
//it to an integer. In this section, I check to see
//if it is 600 hours (6AM) OR 1800 hours (6PM) . If it is not, then I don't jump
//to label "rst", and I end the block.
//***************************

O(L "Daily Reset DB".Hour
BTI
L 6
==I)
O(L "Daily Reset DB".Hour
BTI
L 18
==I)

AN "Daily Reset DB".ResetComplete
JC rst
BEU


//***************************
//If it has reached 6AM or 6PM, I jump to
//"rst", transfer my runtime values to historian, then transfer
//a zero to the runtime variables. I also set the "ResetComplete" bit
//as a way to create a one-shot (see the comparison
//above) so this is only executed once.
//***************************

rst: L "RUNTIME”.Hours
T "Hist_Real”.Hours
L "RUNTIME”.Minutes
T "Hist_Real”.Minutes
L 0
T "RUNTIME”.Hour
T "RUNTIME”.Minutes

SET
= "Daily Reset DB".ResetComplete



- In the OR statements I'm getting a syntax error at "Daily Reset DB"
- At the rst statement I'm getting S identifier goes beyond end of row?

EDIT: I just realized for the OR statements I will need to use not only hours but minutes and seconds if I only want to reset right at 6:00:00AM and 6:00:00. Doing AND/OR is confusing to me in STL so any help would be appreciated.
 
Here's an example project using a different approach to solving your problem. It is based on three shifts but you can ignore the third shift. FC8 is from the Siemens library.
 

Similar Topics

Hi, Is it possible and how to get automated data transfer, what works real-time all the time, from Siemens S7-300PLC to MS excel spreadsheet...
Replies
11
Views
12,954
Dear Experts. I have a CPU 315-2dp Siemens PLC which is communication between mistubishi fX-3U Series mistubishi is giving me AScii String data...
Replies
2
Views
5,939
merry christmas and happy new year i have a click c0-00dr-d and allen bradley 2711c-t3m. can the panelview talk to the click plc via modbus...
Replies
1
Views
215
Hello. There is a problem with Siemens S7 300. We got a replacement PLC but it does not run the program from the MMC. The new PLC is dated 2011...
Replies
3
Views
687
Hi Any one here please helpmein simulation of s7 300 plc program with factory io. how to connect. plcsim 5 doesnot have option of s7 300 ..:
Replies
2
Views
1,009
Back
Top Bottom