Real Time Calc's in SLC5/03

chetezen

Member
Join Date
May 2003
Posts
13
I'm trying to display a "calculated finish time" based on a calculated thruput.
I have a value (hours)which represents my remaining time. This is a calculated value that is displayed as "1.25" for 1 hour 15 minutes.
Based on my clock (in the PLC) I need to "convert" this remaining time to a time value (hh:mm).
I can't seem to find an easy way to do this, so I was hoping somebody out there has a hint for this...
 
I'm not sure if you want the time that it will finish (current time 1:00, finished time 2:30),or if you want to display 1.25 hrs as 1 hr 15 min.

Any way sounds like either scp(scale with parameter) or roll your own scp would work nicely, you would just use the decimal part of the remaining time(possibly needing to convert to a whole #).
The type of plc will have a lot to do with how its done.


Drewcrew6
 
If you are trying to simply convert the fractions of an hour into minutes, the easiest way (in my opinion) is the SCP as drewcrew6 pointed out.

If this is not what you are trying to do please post.

In my example N7:0 is "decimal fraction of hour", and N10:0 is minutes.

scp.gif
 
Step by Step.

Step 1. Convert decimal time to Minutes.
Calculated_Finish_Time (=1.25) x 60 = Minute_Time (= 75)

Step 2. Calculate Hours. Store this value in an integer register, not a float.
Minute_Time (=75) / 60 = HH_Time (=1)

Step 3. Verify Hours didn't get rounded up during division.
IF (HH_Time * 60 > Minute_Time) then HH_Time - 1 = HH_Time
(Conditions are false - no correction is done in this example)

Step 4. With the corrected Hours, calculate the Minutes. The destination should also be an integer register.
Minutes_Time - (HH_Time * 60) = MM_Time.
75 - (1 * 60) = 15

Your final answer is in the integer registers HH_Time (1) and MM_Time (15)

Depending on your PLC brand, you may have to have some interim calculations (such as for HH_Time * 60, used in steps 2 and repeated in step 3)

It is also possible to do the calculation using the MOD math instruction, if you PLC supports it.
 
Last edited:
I have a floating point (F8:20) which represents the remaing time (span) in hours. This number will be displayed as 1.25 when there is one hour and 15 minutes left, as an example.
Now, I need to take this number (F8:20) and add it to the current time (S40:S41) and display a real time value (hh:mm) for calculated finish time. So, if F8:20 is 1.25 and the current time is 4:15, my result (display) should be 5:30.
The SCP instruction is a good help, but I still can'f figure out how to get the F8:20 value converted to hours and minutes, where I can use them in the calculations.
 
basic algebra

We get the decimal representation of 15 minutes by the following:

15 / 60 = .25

Just reverse the operation when you already know the answer by substituting in X for the known variable and solving for X.

X / 60 = .25

X = 60 * .25


Answer:

Multiply by 60 to convert from decimal to minutes
Divide by 60 to convert from minutes into decimal

I think this is right. Could someone please confirm.
 
My mistake!

Your reference to the PLC clock threw me. I originally thought you already had 2 integers; hours and fraction of hours.

Allen's plan is what you're looking for.
 
I noticed you specified the SLC5/03, the DIV of this model does place a rounde quotient in the result register. The Unrounded (truncated) quotient is placed in the upper math register S:14, which will be the hours, for use with Allen's method. To add to current time to display time of completion, brute force, RTC should have hours and minutes in separate words, add each, and check for minutes over 60 or hours over 12 and convert as necessary.
 
chetezen said:
I have a floating point (F8:20) which represents the remaing time (span) in hours. This number will be displayed as 1.25 when there is one hour and 15 minutes left, as an example.
Now, I need to take this number (F8:20) and add it to the current time (S40:S41) and display a real time value (hh:mm) for calculated finish time. So, if F8:20 is 1.25 and the current time is 4:15, my result (display) should be 5:30.
The SCP instruction is a good help, but I still can'f figure out how to get the F8:20 value converted to hours and minutes, where I can use them in the calculations.

If you take S:41 (minutes), in this example 15. Take S:41 and divide by 60. Add this value to S:40 (Hours). You get 4.25. Add 4.25 to your "remaining time in hours" and you get 4.25 + 1.25 = 5.5 (note: do all your addition of time in the decimal format).

The tough part is displaying 5.5 as 5 hours and 30 min. It would be easy if you could just extract the decimal portion and multiply it by 60. I don't know how to easily do this in a plc. Anyone have any suggestions?
 
Your Display device may be able to convert the fractional time representation of 5.5 easier. Most HMI's have the Modulo function which allows you to take "your number " MOD 1 = decimal portion or .5. You could then multiply your remainder by 60 and ignore the remainder and now you have your displayed minutes.

Would be nice to have the Modulo function in a PLC now wouldn't it.

Anyone have plc logic for the Modulo function.
 
I just checked out the Divide instruction in the SLC.

Unfortunately, although the remainder function appears to work, it only stores a whole number remainder.

For example:

On windows calculator:
[17 MOD 4 = 1]

In SLC:
[17 / 4 = 4 remainder 1]

- looks like the DIV instruction would work as a MOD function, but then....

On windows calculator:
[17.5 MOD 4 = 1.5]

In SLC:
17.5 / 4 = "whatever used to be there" remainder "whatever used to be there"

Summary: Remainder function stores a whole number. Does not work when used with floating point numbers. Divide instruction does not work as a mod function.
 
Step by Step by Step

So you want to do more than just convert a decimal time to HH:MM? You want to do time addition as well?

Messy, but the principle I laid out in my first post still applies.

First, convert the duration time decimal hours into integer minutes.

Second, convert the current time into integer minutes.

Next, add the two results together to get the finish time in integer minutes.

Finally, convert the integer minutes to integer hours (like I showed, allowing for the rounding error), and the remainder minutes.

You may want some checks in there so that if the hour component is greater than 13 (or 24, if using military time), then subtract 12 (or 24) from the resultant hour.

But for pity's sake, don't take it further than the time - you'll drive yourself crazy trying to figure out when a 1.5 hour duration started on Feb 28, 2002 @ 11:20 PM will end.

Good luck
 
Yes, there are a lot of extra checks that need to be added to make the hh:mm come out right. It looks like I got it right now, though.
Thanks for the suggestions and inputs
 

Similar Topics

Hi Iam using monitouch hmi(V9 soft) with omron plc cj2m (CX programmer). In this I want to read a data from hmi to plc. The data was like...
Replies
0
Views
73
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,209
Hi all, I'm having an issue with connecting View Studio emulation to a real PLC. I am running View Studio 8.01 on a Hyper-V virtual machine...
Replies
0
Views
233
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
439
Hi fellow automation people, FactoryTalk View SE V13 Network I am trying to setup a generic popup trend where I can switch it between...
Replies
0
Views
167
Back
Top Bottom