Floating Point number

Maia

Member
Join Date
Sep 2004
Location
Laguna
Posts
29
Hi PLC experts,

Using CFC, I configured a logic to totalize a certain parameter which is flow. The totalizer is functioning well except that, when the value reaches a million, the totalized value being displayed seems not accurate. The increment becomes linear. I'm thinking maybe it has something to do with the 32-bit thing of the floating point data type but I'm not sure what exactly is the explanation for that. Can somebody give me an explanation for this?

Please help.

Thanks,
maia
 
A floting point or real use a sign bit, 8 bit exponent and 23 bit mantisse.
Sign: + or -
Exponent: +E001 or -E001
Mantisse: 1.23

Integer 10 is as float 1.0+e001
1.0 x 10 power of 1 = 10

To convert an integer to real use:

L MW10
ITD
DTR
T MD12
 
Hello Maia;

Here is a link to a review of IEEE 754, single-precision 32-bit floating-point values, such as it is used in most PLCs today (with examples):
http://en.wikipedia.org/wiki/IEEE_754

Since floating-point values can attain huge values, i don't think this is your issue here. A value of 1 million is hardly a problem for REAL values.
Please produce an screen capture of your CFC blocks, or better yet an illustration of the logic you are using (along with an exact description or examples of the problems you face), so we can see what we can do to help you.
Hope this helps,
Daniel Chartier
 
The problem that you run into with floats as they get larger is precision. For example, with a 32 bit float, you cannot add 1.0 to 16,777,216 and get 16,777,217 because of the loss of precision as the number gets larger. If you are adding a very small increment, like something around .032, then I suspect that is your problem, as you approach 1 million you begin to loose precision. What are you totalizing and how large is each increment?
 
Thanks Daniel! Thanks Alaric!

Will try to get a screenshot of the block and the logic itself by tomorrow and will post it as soon as I get it.

Alaric - The increment is about 0.284 per second. And I noticed that the value becomes inaccurate when it reaches millions, say 3 million. But when the totalized value is smaller, I don't see any problem. I think you're right, the precision might be the problem. Is there any way to correct it?


maia
 
Is each increment really in the order of 0.284 ?
How big a total value do you need to count to ?

If you are adding a value with increments of 0.284 then you will run into rounding errors long before you reach 3,000,000.0
The largest mantissa value that a REAL can contain is +3402823. That is indeed about 3 million, but the fractional part has begun to become rounded off at a much smaller value.

A DINT can count to +2147483647
So you could interpret it as +2147483.647, in other words as there is a fractional part with 3 decimals. But that will only let you reach 2 million.

It looks like you have to program your own counter by combining several variables.
 
Could you come to a programming get-around solution,like have two additional floating point stores, count in one up to a million, then add the million to the second store and zero the first. The third being your total value, which adds the other two together.
 
You can add the sample (~.284) to one number and periodically sum that to a second floating point number and zero the first, as Peter suggested. You will loose precision, but the overall value will keep incrementing and will still be accurate to whatever significant digits are meaningful for a particualar number in IEEE754 format

You may also want to evaluate the units you are using. For example, if .284 represents liters then you might want to use CCs, or if its cubic-feet then try gallons.
 
Last edited:
Peter Nachtwey said:
Count the number of items you are totalizing using DINT. Multiply the DINT by 0.284 to get desired result. Simple.
Yes, if the increment is constant at 0.284.
But if the increment varies around this value, then you have to count up with a fractional part with at least 3 decimals.
 
But one could totalize the input to a certain value and then count those values, eg, if totalizing cubic meters, totalize the samples until you have more than 1 cubic meter, then increment the count for cubic meters using a DINT and then subtract 1 cubic meter from the running intermediate total. Any convenient unit can be used, even quarter cubic meters, and then multiplied by whatever is needed to scale it to the final units.
 

Similar Topics

We have AOIs for projects, which handle material dosing (by hand or by pipes and pumps), obviously they have comparison between setpoint and...
Replies
50
Views
14,325
What is a good method to take a floating point number and strip off the numbers to the right of the decimal so they can be use in a compare...
Replies
17
Views
4,507
I am working with the ML 1400 to utilize the HSC, I have set it up and can read from my encoder into HSC:0/ACC. However I need to convert the...
Replies
6
Views
1,794
I am trying to display a floating point number on an NT631c. PLC is a CJ1M. I have allocated the floating point number to D112 and set the screen...
Replies
4
Views
2,486
What is the best way to remove the whole number from a floating point so i can do a math function on just the decimal with a allen bradley 5/05...
Replies
3
Views
2,479
Back
Top Bottom