defcon.klaxon
Lifetime Supporting Member
Hi guys,
I am trying to create a very basic totalizer in Logix; I need to keep track of runtime for pumps, their number of starts too; I need daily totals and lifetime totals as well.
After doing a bunch of experimenting with CTU instructions and trying to extract daily and lifetime values I figured I was getting too complicated, and simply resorted to an ADD instruction; I have an RTO pulse every 6 minutes when the pump is running for decimal hours, and each time the pulse occurs I simply add 0.1 to both my runtime tags. At midnight, I reset the daily tag and just let the lifetime tag keep accumulating value.
It's ridiculously simple but it seems to work great...but there's an odd catch. Every time, like clockwork, when I go from 0.6 to 0.7, an error occurs. Instead of simply being 0.7, it's 0.70000005, then after the next pulse the new value is 0.8000001. Then about every fourth pulse, the error occurs again and that miniscule decimal amount in the ten-millionths place changes.
Now in the big scheme of thing, such a small rounding error is probably not going to affect my counter too much, but nonetheless I certainly don't like it. I tried changing the ADD instruction to 0.10000000000000 just to see if having that many zeros might stop the problem, but no dice.
Is this issue a well known problem? Is my code doing something I'm not realizing? I'd really prefer to get this to work right instead of living with this error.
I am trying to create a very basic totalizer in Logix; I need to keep track of runtime for pumps, their number of starts too; I need daily totals and lifetime totals as well.
After doing a bunch of experimenting with CTU instructions and trying to extract daily and lifetime values I figured I was getting too complicated, and simply resorted to an ADD instruction; I have an RTO pulse every 6 minutes when the pump is running for decimal hours, and each time the pulse occurs I simply add 0.1 to both my runtime tags. At midnight, I reset the daily tag and just let the lifetime tag keep accumulating value.
It's ridiculously simple but it seems to work great...but there's an odd catch. Every time, like clockwork, when I go from 0.6 to 0.7, an error occurs. Instead of simply being 0.7, it's 0.70000005, then after the next pulse the new value is 0.8000001. Then about every fourth pulse, the error occurs again and that miniscule decimal amount in the ten-millionths place changes.
Now in the big scheme of thing, such a small rounding error is probably not going to affect my counter too much, but nonetheless I certainly don't like it. I tried changing the ADD instruction to 0.10000000000000 just to see if having that many zeros might stop the problem, but no dice.
Is this issue a well known problem? Is my code doing something I'm not realizing? I'd really prefer to get this to work right instead of living with this error.