I saw where this was discussed last month, but I didn't want to necropost to that thread, and it didn't completely answer my situation.
I have a PLC5 and I am counting an input pulse with an add statement that adds .1 with every positive transition. Now, I read the posts, especially by alaric, where he says that when adding .1, I should be able to get accurate numbers up to 2097152. I am not. In fact, I can't even get to 1 without seeing the plc try to add .0999999 or .1000001 instead of .1. As the accumulated value got larger, it seemed more likely to add too much. For instance, if I take the number up to 999999.0 (it rolls over at 1000000), it'll take only 7 or 8 clicks of the input to get to the rollover point. Even when i started at 10000, it seemed to add .2 about 25% of the time. One more thing. I did not write down where the numbers got messed up, but I do not think it was happening at the same number everytime.
I got a lot better results when I added 1 everytime, and then divided by 10 later for the display. In fact, I didn't see a single error with that setup. But, after reading that I wasn't supposed to be seeing errors until the number got very large, I'm worried that even adding 1 is not safe. So I guess my question is, do PLC5s use an even less accurate form of floating points? Can it reliably add 1 to a floating point value or do I need to just bite the bullet and redesign the counter with integers? This is a legacy system and they are quite wary of letting me make big changes to things they *thought* were working just fine.
thanks for the help,
-jeff
I have a PLC5 and I am counting an input pulse with an add statement that adds .1 with every positive transition. Now, I read the posts, especially by alaric, where he says that when adding .1, I should be able to get accurate numbers up to 2097152. I am not. In fact, I can't even get to 1 without seeing the plc try to add .0999999 or .1000001 instead of .1. As the accumulated value got larger, it seemed more likely to add too much. For instance, if I take the number up to 999999.0 (it rolls over at 1000000), it'll take only 7 or 8 clicks of the input to get to the rollover point. Even when i started at 10000, it seemed to add .2 about 25% of the time. One more thing. I did not write down where the numbers got messed up, but I do not think it was happening at the same number everytime.
I got a lot better results when I added 1 everytime, and then divided by 10 later for the display. In fact, I didn't see a single error with that setup. But, after reading that I wasn't supposed to be seeing errors until the number got very large, I'm worried that even adding 1 is not safe. So I guess my question is, do PLC5s use an even less accurate form of floating points? Can it reliably add 1 to a floating point value or do I need to just bite the bullet and redesign the counter with integers? This is a legacy system and they are quite wary of letting me make big changes to things they *thought* were working just fine.
thanks for the help,
-jeff