S7 duration time

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi'

I have to words (Int format), these words contains a number that indicates a start and stop time.

Start time 1330 stop time 1515, is it possible to subtract these 2 values and display them i time left 0145 (Hours Minutes) ?

Regards

Brian
 
Not sure what you are doing here, how are the INT's used as a time value?

If INT=1330 = half past one in the afternoon, you must have some software converting this number, how else can you use it as all time functions must be in a recognised time format.

So what are you doing here?
 
Sorry that I did not make self clear, it is not an issue how I control start and stop time but how to subtract 2 values in TIME or S5TIME and then mabye convert them to integer.


Brian
 
Brian

Forget S5TIME now! It is an awful data-type and should not have been allowed to survive in to this century. It would have been kinder for it and us if Siemens had killed it when S7 was launched.

TIME is easy. Although the IEC specified TIME as a unique data-type it is actually a 32-bit variable holding a number of milliseconds. You can add or subtract TIME variables in STL using double integer arithmetic.

Regards

Ken
 
I'd think over carefully of using a TIME data type. What happens if the beginning is at let say 23.00 and the end at 00.20 (but the following day). I'd suggest a DT (date and time) data type. And there's a function for substracting it in Step7 (see IEC library).

Regards,
 
The IEC definition of a TIME type does take in to account the concept of negative time ("But Captain, the dilithium crystals will never take it!!") so subtracting 2300 from 0020 won't in itself cause an operating system or instruction error.

Obviously the convention we humans use for an elapsed time period covering more than one day is to add in the additional measurement of date along with time. So a DATE_AND_TIME data type could make more sense.

Equally, what's to stop a brief check on whether StopTime is less than StartTime (e.g. 0020 and 2300) and, if so, add 24 hours (or 86,400,000 milliseconds) to StopTime? That keeps it all within the bounds of double integer arithmetic with no need for extra FCs.

Regards

Ken
 
Ken M said:
...what's to stop a brief check on whether StopTime is less than StartTime (e.g. 0020 and 2300) and, if so, add 24 hours (or 86,400,000 milliseconds) to StopTime?

And what if the difference between Start and Stop is more then 2 days ? This is not about human perception of time but about solving problems in a proper way.

Ken M said:
...no need for extra FCs...

BNA seems a liitle bit new to S7 world, so I prefered to show him ready-made solution than kind of DIY.

BTW, to be exhaustive: TIME format can cover time difference up to 2^31-1 miliseconds (ca 25 days). If duration greater then that is expected one has to work out other solution than mentioned FC.
 
Sorry, sorry, sorry...I was originally trying to answer the question which had been asked
how to subtract 2 values in TIME or S5TIME
Sure, you can tell him how to subtract DATEs but this is not what he asked. Why didn't you tell him how to multiply REALs - he didn't ask that either;)

Regards

Ken
 
BNA said:
Hi'

I have to words (Int format), these words contains a number that indicates a start and stop time.

Start time 1330 stop time 1515, is it possible to subtract these 2 values and display them i time left 0145 (Hours Minutes) ?

Regards

Brian

Hi
try to use:
FC34 SB_DT_DT
Description
The function FC34 subtracts two time values (format DT) and provides a duration (format TIME) as the result. The times must be in the range from DT#1990-01-01-00:00:00.000 to DT#2089-12-31-23:59:59.999. The function does not run an input check. If the first time (parameter T1) is greater (more recent) than the second (parameter DT2), the result is positive; if the first time is smaller (less recent) than the second, the result is negative. If the result of the subtraction is outside the TIME range, the result is limited to the corresponding value and the binary result (BR) bit of the status word is set to “0".
Parameter Declaration Data Type Memory Area Description
DT1 INPUT DATE_AND_TIME D, L First time in format DT
DT2 INPUT DATE_AND_TIME D, L Second time in format DT
RET_VAL OUTPUT TIME I, Q, M, D, L Difference in format TIME
You can assign only a symbolically defined variable for the input parameters.

good luck!
 

Similar Topics

It is said motors are can be overloaded for a duration of time but I can not find a document or formula which clearly states how long I can...
Replies
8
Views
3,151
Hi All, I have a rather simple task, but have no experience with the Timedate library so posting here. How can I calculate the time duration...
Replies
14
Views
3,409
Hi, I have a application where I need to calculate the time to complate a servo position move, the values I have is: acceleration which is...
Replies
11
Views
2,787
Hi I want to calculate the time duration of a high pulse in milliseconds in ST language.It would be very helpful if I get the proper suggestion...
Replies
15
Views
4,819
Good day for all of you. I got a Historical trend i have configured on a QuickPanel+: Scan rate : 30.0, Pixel scale: 1 with the purpose of...
Replies
0
Views
1,977
Back
Top Bottom