Subtracting minutes from time stored as a decimal.

Ah... I see, so it's not an accumulated time for break but a break time.
I need to think about this one. Converting a time field to double integer would convert it to milliseconds. it seems you have some complex logic that is comparing the actual time with a field that is not time related.
 
yes it converts time that production can enter into a PC into this value in a DINT. But if the time is 1100 (11:00am) when I subtract 2 minutes from it I get 1098 instead. The big one comes at 12:00am because if I subtract two minutes from this I need it to say 2358 (11:58pm)
 
yes it converts time that production can enter into a PC into this value in a DINT. But if the time is 1100 (11:00am) when I subtract 2 minutes from it I get 1098 instead. The big one comes at 12:00am because if I subtract two minutes from this I need it to say 2358 (11:58pm)




add 2400 before the subtract, do the extra subtract of 40 if the subtrahend minutes are greater than the minuend minutes, then do modulo 2400 at the end.


this belongs in an AOI where cleaner conditional logic is available; yes it could be done in a CPT but it will be ugly there, IMNSHO.


Just be glad you have the MOD instruction.
 
turn them on again automatically two minutes before the end of their break.


I am extrapolating here so I may be way off:

  • the automatic routine is doing the "subtract 2" from the HMM break times,
  • and comparing that to an HMM representation of the current time,
  • which current time it is presumably getting from the RTC, as separate hours and minutes
Have you considered adding two minutes to the minutes, and doing the [modulo 60/add 1 to hours MOD 24] there, and comparing that to the unmodified HMM break time?
 
Yes, I have a RTC hours *100 plus RTC minutes to get a value of the current time to match up with how our system keeps track of it.


So if I am to understand what you are saying, is to spoof the current time signal to get what I want instead of subtracting from my target time setting?
 
Yes, I have a RTC hours *100 plus RTC minutes to get a value of the current time to match up with how our system keeps track of it.


So if I am to understand what you are saying, is to spoof the current time signal to get what I want instead of subtracting from my target time setting?


yes, the math for adding may turn out cleaner, I dunno, because you have a separate minutes value a priori, i.e. from the RTC, instead of having to extract it from the HMM value.


so


Code:
if RTC_minutes < 58 then
  hmm = RTC_hours * 100 + RTC_minutes + 2
else
  hmm = RTC_hours * 100 + RTC_minutes + 42
 endif
or even


Code:
 hmm = (RTC_hours * 100) + RTC_minutes + 2 + ((RTC_minutes > 57) * 40)
N.B. Assumes (RTC_minutes > 57) evaluates to integer 0 if false or integer 1 if true.


Also, you could do the [minus 2minutes] operation once, when the break time is set, stored in a separate var, and compare [RTC h * 100 + RTC min] directly.


I don't think it will be pretty either way.
 
Last edited:
Why not convert the time into integer (this gives it in ms) then subtract 120,000 from it & convert back to time. (I have no idea if RSL has Time to Dint or Dint to time) but that seems the easy way.
 
I suspect there is an existing convention that interprets the DINT decimal digits' representation as a time in 24h time HHMM format, and that convention is used elsewhere; it's okay for straight-up EQU, LES, LEQ, GRT, and GEQ comparisons; it's just ugly if offsets are involved. Changing that convention to a different framework that handles offsets cleanly would involve a lot of extra effort anywhere else the old framework is in use; the OP is only looking for a clean way to deal with offsets in the existing system. That's my guess anyway.



Hey, at least it's not BCD!
 
This should work:

Code:
hour:=(shifttime/100)*100;
minute:=shifttime-hour;
IF minute-2<0 Then
		minute:=60+((minute-2)MOD 60);
		hour:=(((shifttime/100)-1)MOD 24);
		IF hour<0 THEN 
			hour:=(24+hour)*100;
		ELSE
			hour:=hour*100;
		END_IF;
ELSE
		minute:=minute-2;
END_IF;
offsettime:=(hour+minute);
 
This should work:

Code:
hour:=(shifttime/100)*100;
minute:=shifttime-hour;
IF minute-2<0 Then
        minute:=60+((minute-2)MOD 60);
        hour:=(((shifttime/100)-1)MOD 24);
        IF hour<0 THEN 
            hour:=(24+hour)*100;
        ELSE
            hour:=hour*100;
        END_IF;
ELSE
        minute:=minute-2;
END_IF;
offsettime:=(hour+minute);


should that last line perhaps be


Code:
offsettime:=(hour*100)+minute;
?


Also the first line:
Code:
hour:=(shifttime/100)/100;
will not work if the divide result is rounded instead of truncated; better, since MOD is available, to replace first two lines with these:
Code:
minute:=shifttime MOD 100;
hour:=(shifttime-minute) / 100;
That said, I think this is the kind of "clumsy ... on and on and it seems excessive" solution the OP is trying to avoid.
 
Last edited:
Storing a time variable as a DINT in the format HHMM is the real problem. Everything else is just masking the problem.


Of course.


Maybe a decision was taken to have operators enter a time, as hours and minutes, via a single 1- to 4-digit number, and that is the overriding concern; all of the problems blossomed from there, but the OP is still stuck looking for a cleaner way to handle it.


As others have said, the cleanest approach would be to convert the HHMM DINT as soon as it is entered to, and store it as, minute-of-day (0-1439), and then there is a simple conversion from RTC hours and minutes to the same scale that has a simple formula for adding 2: ((RTC_hours * 60) + RTC_minutes + 2) MOD 1440; or subtracting by replacing that 2 with 1438.
 
Last edited:
"Have you looked at the AOIs in the Add_On_Instructions_Samples that comes with v19? It has several functions that address math and time."

That, to me, is your best route. This problem has already been solved, placed in an AOI box, and gift wrapped. When you have the opportunity, always take the easy way out.


Bubba.
 

Similar Topics

Hi I am trying to find the simplist way to add/subtract/multiply/divide from all the dint's in a 42dint array. The timing on our main oven loads...
Replies
3
Views
2,991
Hello: I'm working in the Connected Component Workbench environment with a Micro820 PLC. Is there a way to add-subtract date & time values. Thanks
Replies
7
Views
3,516
Basically I have a digital value I need to scale down using this equation: 'end_value = (D1-1000)/100' but I'm having trouble writing it down to...
Replies
3
Views
2,160
in a slc 5, Is there a way to subtract one counter acc from another one and then say if the subtraction is over 5 that it would trigger and output...
Replies
3
Views
1,583
Rslogix 500 Im trying to subtract 10 from the level of a tank we have and then use a less than or equal compare to start a pump. How can I...
Replies
11
Views
2,045
Back
Top Bottom