Day and Time comparison S7

Nepiter

Member
Join Date
Apr 2010
Location
At job
Posts
79
I'm using S7-317 cpu's SFC1 function, and having some questions about that area..

I need to set bit at 9.00 and reset bit 18.30.

For that, I have converted time from SFC1 (db1.dbw3 hh:mm) BCD->INT .
Also I have converted set-time and reset time BCD->INT.
Now I should be able to compare time.

But I have small problem:

When I convert BCD to INT, time 18.30 is same as 8.30.
time 18.30 = hex:1830, INT:830
time 08.30 = hex:0830, INT:830

So, my comparison does not work that way.
Any ideas what is wrong?

P.S. Any ideas why my Date and Time will not give a day of week at byte 8? It is changing rapidly between 25 and 66.
 
Last edited:
Use FC8 from the standard library>IEC functions to extract the time of day from the date and time, you can then do your comparisons.

Example function block:

Code:
FUNCTION_BLOCK FB 1
TITLE =
VERSION : 0.1


VAR_IN_OUT
  bBitToControl : BOOL ;    
END_VAR
VAR
  bSetEdgeStore : BOOL ;    
  bResetEdgeStore : BOOL ;    
END_VAR
VAR_TEMP
  datDateAndTime : DATE_AND_TIME ;    
  iSFC1ReturnValue : INT ;    
  todTimeOfDay : TIME_OF_DAY ;    
END_VAR
BEGIN
NETWORK
TITLE =

      CALL SFC    1 (
           RET_VAL                  := #iSFC1ReturnValue,
           CDT                      := #datDateAndTime);

      CALL FC     8 (
           IN                       := #datDateAndTime,
           RET_VAL                  := #todTimeOfDay);

      A(    ; 
      L     #todTimeOfDay; 
      L     T#9H; 
      >D    ; 
      )     ; 
      FP    #bSetEdgeStore; 
      S     #bBitToControl; 

      A(    ; 
      L     #todTimeOfDay; 
      L     T#18H30M; 
      >D    ; 
      )     ; 
      FP    #bResetEdgeStore; 
      R     #bBitToControl; 

      SET   ; 
      SAVE  ; 
END_FUNCTION_BLOCK
 
Many thanks!
That solved the problem with time comparison!

If any ideas with byte 8 (day of week) I would be interested.
 
in Byte 7 with the 4 "Most Significant Bits" (MSB) for milliseconds and the 4 "Last Significant Bits" (LSB) for day of week

Day of week:
1: Sunday,
2: Monday,
3: Tuesday,
4: Wednesday,
5: Thursday,
6: Friday,
7: Saturday
Datum_Uhrzeit_mit_SFC_ein_u_auslesen_01_e.gif
 
Last edited:

Similar Topics

Per title - what's the worst and best wire duct brands you have worked with, and why? They all look the same on the outside, but there are...
Replies
13
Views
2,425
I have installed a Cognex barcode scanner on a machine. I have a 1769-L18ER CompactLogix processor. I have communication setup and working. I...
Replies
26
Views
4,643
Is there anyway to be certain that the memory module in a ML1400 has been written to with the current program? I have controllers in the field...
Replies
0
Views
875
Hello all, I'm trying to come up with an elegant solution to check an Array of Values to see if they are greater than zero but less than 15 My...
Replies
11
Views
2,371
Hello experts; If i want to compare two companies PLC's features which points should be considered especially if i want to compare Siemens and...
Replies
9
Views
2,536
Back
Top Bottom