Siemens S7 into to TOD

cjd1965

Lifetime Supporting Member
Join Date
Apr 2007
Location
UK
Posts
1,659
Hi
I have a MP377 and S7-300

I have a grid of days of the week and times for each day. The times are ints for hrs and mins (hrs=24hr clock)

How can I convert the ints to TOD for comparison with the returns of FC7/8 IEC functions?

Is this just a question of multiplying my ints to get m/secs?
 
Hi From what I can tell it is just a case of converting the hours and minutes required to milliseconds and adding together to get the TOD for a particular day so i will try that out tomorrow

Cheers
 
Hi this is what i came up with, seems to work OK but maybe not the best way


Code:
FUNCTION "INT To Time" : VOID
TITLE =
{ S7_language := '9(2) English (United Kingdom)  25.10.2009  15:07:45' }
VERSION : 0.1
 
VAR_INPUT
  Duration_Hr : INT ; 
  Duration_Min : INT ; 
END_VAR
VAR_OUTPUT
  RunTime : TIME ; 
END_VAR
VAR_TEMP
  Dint_Duration_Hr : DINT ; 
  Dint_Duration_Min : DINT ; 
  Dint_Duration_Hr_T : DINT ; 
  Dint_Duration_Min_T : DINT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      A(    ; 
      L     #Duration_Hr; 
      ITD   ; 
      T     #Dint_Duration_Hr; 
      SET   ; 
      SAVE  ; 
      CLR   ; 
      A     BR; 
      )     ; 
      JNB   _001; 
      L     #Dint_Duration_Hr; 
      L     L#3600000; 
      *D    ; 
      T     #Dint_Duration_Hr_T; 
_001: NOP   0; 
NETWORK
TITLE =
      A(    ; 
      L     #Duration_Min; 
      ITD   ; 
      T     #Dint_Duration_Min; 
      SET   ; 
      SAVE  ; 
      CLR   ; 
      A     BR; 
      )     ; 
      JNB   _002; 
      L     #Dint_Duration_Min; 
      L     L#60000; 
      *D    ; 
      T     #Dint_Duration_Min_T; 
_002: NOP   0; 
NETWORK
TITLE =
      L     #Dint_Duration_Hr_T; 
      L     #Dint_Duration_Min_T; 
      +D    ; 
      T     #RunTime; 
      NOP   0; 
END_FUNCTION
 
Here's an STL implementation:

Code:
      L     #Duration_Hr
      L     60
      *D    
      L     #Duration_Min
      +D    
      L     L#60000
      *D    
      T     #RunTime
 
Hi
Thanks for that.. it is much more compact.

However shouldnt 60 be 3600000 to convert hours to milliseconds or am i missing a trick somewhere

EDIT
I just read read it and your correct.. I missed the conversion of hrs to minutes when i first looked

Cheers
 

Similar Topics

I am using Tia Portal I used a block to write to the system time and it made it the TOD? Why does the TOD show up as a Double what type of data is...
Replies
5
Views
4,098
Hello Could someone please help me with this query? I need a TOD value to be written to an s7-300 PLC from a SCADA. I have already created a...
Replies
2
Views
2,956
The past week we received a new piece of equipment from Germany which utilizes siemens controls. Typically in our company we use A.B. controls for...
Replies
6
Views
109
Hello I have a s7-1200 and I would like to read the tags present in this controller with my controllogix controller. The two controllers don't use...
Replies
5
Views
127
Hi need help why this “failure 5 emergency stop “ appears at every startup in the morning ? Have to shut off main switch at least 10 times on...
Replies
19
Views
290
Back
Top Bottom