Showing Remaining Minutes and Seconds on and HMI

Usually I just display the three Integers I create in the PLC, separate, but formatted on the screen so they are close together with either wording or a fixed ":" in between them. It appears as one display, but in reality is three separate ones.

Try to make things as independent from the HMI as possible. Were the HMI is merely a device to display things, rather than actually do any logic. I think it leaves me open to switching brands and applying basic usage cross multiple brands, but that is just my preference.

I agree. K.I.S.S as they say.
 
"forcing" rounding down (or up), is therefore no longer simple in Logix5000 platforms.

Should be just as simple. Doesn't matter how or when it rounds, my exampled logic doesn't care. It only cares if the rounded number result is greater than the original number.

Original Float converted to Rounded Integer. (What ever rounding rules the PLC uses)

If Rounded Integer > Original Float, Subtract 1.

Depending on your PLC, you may need to convert Rounded Integer into a Floating Point before compare, but the 500/5000 PLC range from AB does type conversions automatically. But even if you have to convert it first, the logic still works.

If for some reason you wanted to force a round up, you'd just compare the other way and add 1 instead.
 
Usually I just display the three Integers I create in the PLC, separate, but formatted on the screen so they are close together with either wording or a fixed ":" in between them. It appears as one display, but in reality is three separate ones.

I agree. K.I.S.S as they say.

Because I'm "that" guy... K.I.S.S is relative.

This method seems simple however my experience seeing this method implemented in the field leaves me less than impressed. It's very clunky and dependent on how anal a programmer is. Usually what I see on the HMI/SCADA screen the HH, MM, SS values and ":" are not spaced properly, or vertically/horizontally aligned properly. There is also a tendency to drop leading zeros. While "functional" and gets the job done it's not visually appealing, I find it a bit distracting. Who ever sees a time stamp of "2:3:9"? Not saying that's what anyone here does, but what I've seen over the years.

It's also not very scalable, if you need to display say 100+ timers with this format adding all the logic in the PLC just to give it a nice HH:MM:SS (including leading zeros) format is a bit much IMHO. Great example where one could make an argument that a K.I.S.S solution might exist outside the PLC.

Just playing devil's advocate.
 
I've been thinking about this some more today, and am curious about the rounding error people are talking about. Why introduce floating point in the first place? If you keep it all as DINT, any fractional result from a DIV instruction is truncated, not rounded. Which for time purposes seems ideal.

Example, say my timer is currently has an ACC value of 10,799 seconds.

10,799/3600 = 2.9997 hours, resulting in a DINT value of 2 (2 hours but not 3).
10,799/60 = 179.983 minutes, resulting in a DINT value of 179. (Subtract the 2 hours) = 59 minutes

So far 2 hrs, 59 minutes.

10,799 - (2 hrs * 3600) - (59 min * 60)

= 10,799 - 7200 - 3540

= 59 seconds.

Concatenate w/some formatting: 02:59:59

Using 10,801
10,801/3600 = 3.000278 hrs, DINT value of 3

10,801/60 = 180.0167 mins, DINT value of 180. (subtract 3 hrs) = 0 Minutes.

10,801 - 10800 - 0 = 1 Sec.

Concatenate w/some formatting: 03:00:01
 
Should be just as simple. Doesn't matter how or when it rounds, my exampled logic doesn't care. It only cares if the rounded number result is greater than the original number.

Original Float converted to Rounded Integer. (What ever rounding rules the PLC uses)

If Rounded Integer > Original Float, Subtract 1.

....

If for some reason you wanted to force a round up, you'd just compare the other way and add 1 instead.

Tharon, there isn't a "one solution fits all" - You have to qualify what "rounding" you are wanting to achieve...

Round Down (lesser result)
Round Up (higher result)
Round towards Zero
Round away from Zero

You also need to check that the subsequent "add 1" or "sub 1" in your methods don't exceed the limits of your data-types. One day, when you've long forgotten about the application, the numbers might just be....

32,767.35 >MOV> 32,767 + 1 = -32,768 !!!

Everything is obviously application dependent, but I hope it illustrates the thought processes that a programmer should go through when dealing with any number manipulation.

To summarize the differences between the methods, take a look at the following pic from an excel spreadsheet I threw together, and you will see that everything is not nearly as simple as has been suggested..... The highlighted cells show the difference between the Logix500 and 5000 rounding algorithms.....

2016-10-28_131003.jpg
 
..... If you keep it all as DINT, any fractional result from a DIV instruction is truncated, not rounded. Which for time purposes seems ideal.

Example, say my timer is currently has an ACC value of 10,799 seconds.

10,799/3600 = 2.9997 hours, resulting in a DINT value of 2 (2 hours but not 3).
.
.....

Yes indeed.... You have pointed out that Logix processors have two distinct sets of math routines, sort of like two different calculators.

If all arguments of a math instruction are integer data-type, then faster, integer-only, math routines are used. These ALWAYS ignore any fractional part, and return a truncated result.

If, however, at least one of the arguments is a Float or Real, then ALL the arguments are converted to floating-point, and the slower floating-point math routines are used. These WILL return a floating-point result. It is then that the instruction looks at where the result is to be stored, and performs rounding if required (destination is an integer address or tag).

Of course, that rounding may yield different results across different platforms......

Logix500....
5 DIV 2 = 2 (truncated result)
5.0 DIV 2 = 2.5 (fp dest.) or 3 (int dest., rounded result)

Logix5000....
5 DIV 2 = 2 (truncated result)
5.0 DIV 2 = 2.5 (fp dest.) or 2 (int dest., rounded result)

These facts come as a surprise to many people I train....
 
Daba, I'm looking at your spread sheet and from what I can tell, it shows exactly what I said. The A>B -1 or A<B +1 methods yield the same results whether it is a 5000 or 500 plc.

So I don't see why it matters if you are using a 5000 vs 500, as you had mentioned, when my logic yields the same results on both platforms.
 
Daba, I'm looking at your spread sheet and from what I can tell, it shows exactly what I said. The A>B -1 or A<B +1 methods yield the same results whether it is a 5000 or 500 plc.

So I don't see why it matters if you are using a 5000 vs 500, as you had mentioned, when my logic yields the same results on both platforms.

Yes, I wasn't particularly saying your methods worked differently. I had already mentioned that there are more ways than one of "Rounding" - take a look at the figures produced by Excel for its various methods, at least they give them different names.

When I said "To summarize the differences between the methods", I should have perhaps qualified it better, by saying "To summarize the differences between various rounding methods".

My comment about limit checking still applies though....
 
Here is my take on it, wrap it up in an AOI. timeInSeconds tag as an input DINT, timeHHMMSS as an InOut STRING Declare remaining tags as local, either DINT or STRING.

PLC does all the work, outputs it in a nice "HH:MM:SS" string tag for use on an HMI.

Code:
// Initialize a string tag to hold the ":" character.
// Use ASCII definition of '58' to populate the tag
strColon.DATA[0] := 58;
strColon.LEN := 1;

// Initialze a string tag to hold a "0" character.
// Use ASCII definitiion of '48' to populate the tag
// Used for inserting a leading zero when needed.
strZero.DATA[0] := 48;
strZero.LEN := 1;

// Translate the time represented by seconds, into hours, minutes and seconds
// DINT place holders.
Hours := (timeInSeconds / 3600);
Minutes := (timeInSeconds / 60) - (Hours * 60); 
Seconds := timeInSeconds - (Hours * 3600) - (Minutes * 60); 

// Covnert DINT Hours into a string
DTOS(Hours,strHours);

// Check the string length, if 0 populate the hours
// string with "00"
IF strHours.LEN = 0 THEN
	CONCAT(strZero,strZero,strHours);
// Prefix leading zero if the string length is only 1 
ELSIF strHours.Len = 1 THEN
	CONCAT(strZero,strHours,strHours);
End_If;

// Convert DINT minutes into a string
DTOS(Minutes,strMinutes);

// Check the string length, if 0 populate the minutes
// string with "00"
IF strMinutes.Len = 0 THEN
	CONCAT(strZero,strZero,strMinutes);
// Prefix leading zero if the string length is only 1 
ELSIF strMinutes.LEN = 1 THEN
	CONCAT(strZero,strMinutes,strMinutes);
End_If;

// Convert DINT seconds into a string
DTOS(Seconds,strSeconds);

// Check the string length, if 0 populate the seconds
// string with "00"
IF strSeconds.LEN = 0 THEN
	CONCAT(strZero,strZero,strSeconds);
// Prefix leading zero if the string length is only 1 
ELSIF strSeconds.LEN = 1 THEN
	CONCAT(strZero,strSeconds,strSeconds);
End_IF;

// Series of CONCAT statements to create the final
// "HH:MM:SS" format. Note, do not update the 
// final timeHHMMSS tag until the entire string has been
// concatanated. 
CONCAT(strHours,strColon,strJunk);
CONCAT(strJunk,strMinutes,strJunk);
CONCAT(strJunk,strColon,strJunk);
CONCAT(strJunk,strSeconds,timeHHMMSS);
 
Usually what I see on the HMI/SCADA screen the HH, MM, SS values and ":" are not spaced properly, or vertically/horizontally aligned properly. There is also a tendency to drop leading zeros. While "functional" and gets the job done it's not visually appealing, I find it a bit distracting. Who ever sees a time stamp of "2:3:9"? Not saying that's what anyone here does, but what I've seen over the years.

+1

Seems a shame to waste PLC time/ladder just to format a timer for the HMI.
I would say that data calcs should always be done in the PLC; keeps it consistent and much easier to change/replace HMI later on. But...


What if you want a time zone change?
12h to 24h? (ok, not what the OP asked, but expanding the idea)
Leading zeros? 02:03:09


With the PLC making the time tags you would have to "fix" those three in the HMI anyway.
Some HMIs will just take the timer tag and display it in the HH:MM:SS format; no PLC code, no crazy formulas.

Why punish the PLC with the HMI's job?
 
Why punish the PLC with the HMI's job?

Exactly... just give the HMI the raw data as efficiently as possible (include the data into an existing array), and let the HMI deal with it....

If you see misaligned numeric data fields, misaligned ":" characters, or blanks where there should be leading zeroes, then you know which programmer to point the finger at.

Constructing "string" data in the PLC for the HMI or SCADA to display correctly is not "wrong", sometimes the HMI forces you to do it, but it's not "right" either....

This is just a time display.... "display" being the operative word here, creating a human readable display of any data is not the PLC's job, it's the job the HMI (Human Machine Interface) was intended to do... If it can't do it successfully, then it's not a good HMI.
 
Last edited:
I have the opposite philosophy. I try to keep as much of the manipulation in the PLC as possible. One source modifying data. I dislike finding a project where something, even something simple, is being manipulated by the HMI. I don't even like simple numeric scaling being done on the HMI, even though many brands have it as an option.

And three numbers to display to the HMI is simpler logic in the PLC than ASCII conversions and string concatenates to add appropriate ":" marks. I can manipulate formatting and alignment on the screen so it looks just as good as a single element. The results also seem to be more useful across a wider range of brands. In the 11 years I've been at my current job, I've had to switch HMI brands three times (first time my choice... Bye bye PB32), which involves eventual replacement of older machine HMIs with newer, different brands.


(This does not account for more complicated systems where things like databases and such are being stored outside the PLC. There are many advantages to an external database vs stored data in the PLC).
 
Last edited:
I have the opposite philosophy. I try to keep as much of the manipulation in the PLC as possible. One source modifying data. I dislike finding a project where something, even something simple, is being manipulated by the HMI. I don't even like simple numeric scaling being done on the HMI, even though many brands have it as an option.

And three numbers to display to the HMI is simpler logic in the PLC than ASCII conversions and string concatenates to add appropriate ":" marks. I can manipulate formatting and alignment on the screen so it looks just as good as a single element. The results also seem to be more useful across a wider range of brands. In the 11 years I've been at my current job, I've had to switch HMI brands three times (first time my choice... Bye bye PB32), which involves eventual replacement of older machine HMIs with newer, different brands.

I believe your second paragraph reinforces what I said, just pass 3 numbers to the HMI. Put them on the screen as 2 digits with leading zeroes, and put some static ":" between them.

- what could be simpler.....
 
Sorry, I must have got a bit confused on the couple replies, and the confirmation and raw data mentioned in your first paragraph. Thought you were in the "let the HMI manipulate it and put the time in Hours:Minutes:Seconds" format.
 

Similar Topics

Processor : PLC5 I have an situation where I need to set a time into the Panelview HH:MM:SS (N7:10, N7:11, N7:12). This time is the total time...
Replies
4
Views
4,239
Good morning, We've had an issue with a couple of servo valves and was wondering if anyone had seen anything similar. After a drop in pressure...
Replies
2
Views
125
Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
7
Views
442
Hello. I am working in FTVSE v8. I have many trends set up some of them work others do not. The ones that don't work show the foot print of the...
Replies
3
Views
251
Hello everyone, I am working in a platform and we installed FTV CLIENT SE V 12 IN ALL THE CLIENTS COMPUTERS, we have 6 clients and only 1 is not...
Replies
0
Views
116
Back
Top Bottom