PLC-5 Float Values Totalizing

RMJustin

Member
Join Date
Feb 2015
Location
Michigan
Posts
3
I have an issue with an inherited PLC-5 program on a 5/80E processor. I think I know what the issue is, but can't quite put it into words to explain it to others.

The program is totalizing flow values via some math in a CPT block (that uses the scan time from the PLC (S:8, around 40ms) as update the time component) this outputted snapshot value (F28:25) is then the "Source A" in an ADD block that is added to a float value (F28:280) in "Source B", then the F28:280 tag is used again as the "Dest" of the ADD block. Seems pretty standard operation for all of the PLC's at this site, and they have had no complaints in the past on data being incorrect. These totalizers were typically reset before reaching a value of 7.000 (million gallons). Recently we have been doing some testing and the totalizers appear to lose their resolution at larger values and the totalized value "slows down" even though the flow that is being totalized remains constant. They appear to stall out entirely at values approaching 16.000.

I'm thinking the small snapshot value (around 5.00E-007) is too small to register with the F28:280 Float once the totalized value it holds rolls over into two digits left of the decimal. Does this make sense? I can't think of any other reason that a Float would just quit climbing. Thanks in advance!
 
just as an experiment ...

set up a simple ADD instruction - to take something like F8:0 - then ADD the value 1 to it - and put the answer/destination back to F8:0 ...

if I remember correctly, the value will stop incrementing at 16,777,216 - and just freeze there ...

without seeing your code, I'm betting (pocket change only) that effect is part of your problem ...

so ...

your "maybe?" idea is probably correct ... trying to add small values to a Floating Point type location eventually quits "adding" due to "round-off" issues ...
 
Last edited:
32 bit floats only have a significand 24 bits wide, which corresponds to 7.225 decimal digits. Once you try to go beyond a 7 digit range, things stop working.
In simpler terms, you can effectively add 0.1 to 1,000,000, but adding 0.01 to 1,000,000 would fail.
 
Split the count into gallons and 1000 gsllons..each time you exceed 1000 gallons, add 1 to the thousand gallon accumulator, subtract off 1000 to the regular accumulator. You can recombine them back into a single accumulator using CPT.
 
Thanks to everyone above. I think you are pretty much confirming my suspicions about the decimal location, but explained it better than I could. Now lets see if I can make the same code change 50 times in a row without making a mistake!
 
Three other options: (1) do the totalizing in a selectable time interrupt (STI) routine with a period somewhat longer than the scan time, (2) if the flow value is coming from an analog module that has real-time sampling capability, trigger totalizing off the module, or (3) carefully use a timer to totalize the flow value. These approaches all rely on adding a larger value to the totalizer sum, avoiding loss of precision as it get large. Since it sounds like you might be editing 50 CPT instructions, there might be a way to leverage a change in trigger timing like this to minimize editing (though, if the CPT equation directly references S:8, you are out of luck in this regard).
 

Similar Topics

The topic of reading or writing floating-point values via Modbus seems to come up regularly, and it is to my mind not that difficult. That said...
Replies
0
Views
1,386
Hi, On a previous thread I asked about how to connect a float switch to a PLC. http://www.plctalk.net/qanda/showthread.php?t=126829 As I'm a...
Replies
18
Views
5,608
Dear All, I using Delta PLC DVP-16EH002T to communicate with Power Metter Selec MFM-384. I have problem during reading float type register, I...
Replies
4
Views
4,211
Good Day to all of you, this is my first post, i will try to explain as best as possible, english is not my natural language. I am performing an...
Replies
0
Views
19
Hi All, Someone at work has put a PLC system on my desk, that's just been taken off an idle production line. He said "It's an S7 PLC. We don't...
Replies
3
Views
80
Back
Top Bottom