job517 Posted October 13, 2021 Report Share Posted October 13, 2021 Hi I am new to this forum so bear with me if I am not respecting some of your rules. I have encountered an issue working with data table. I m writing a real value to a data table, but the value displayed on the HMI is different from the original value. you can see in the attached images what I am describing. How can I prevent this ? My controller is a unistream USC B5 TR22. Thank You in advance Quote Link to comment Share on other sites More sharing options...
dierkens Posted October 13, 2021 Report Share Posted October 13, 2021 That's a difference of 0.000038467575848% . How accurate are you expecting ? What data types are they set to? If I need accuracy in the numbers I always collect it with the highest resolution data type (16-bit, 32-bit, 64-bit) I can, then I force the values to a resolution using a round/truncate function that fits the requirements. Example: My required scaling is 0.00 - 100.00. I'll carry my collection out to 123.123456 then round/truncate to 123.1234-> xxx.xx Quote Link to comment Share on other sites More sharing options...
MVP 2022 Joe Tauser Posted October 13, 2021 MVP 2022 Report Share Posted October 13, 2021 +1 on what @dierkens says. That is the downside of a REAL value. They are way more precise than most of us need. Have you considered using integers for everything? They are much more predictable and manageable and a Long type can handle almost any number occurring in our world. I only use REALs when complex calculations are involved, like trig functions. Joe T. Quote Link to comment Share on other sites More sharing options...
job517 Posted October 14, 2021 Author Report Share Posted October 14, 2021 Thank you both @Joe Tauser and @dierkens I am using Real data type because I have to keep track of liters reading input by the operator. It has to be REAL data type since the reading is of the form 12345,12. But now with the inaccuracy of the REAL data type, summing up these values does not reflect the actual real world situation. @dierkens did mention a difference of 0.000038467575848% but i have seen value like 10.7 be saved as 10.625. Are there rounding functions I can use to solve this issue? Thanks again Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted October 14, 2021 MVP 2022 Report Share Posted October 14, 2021 3 hours ago, job517 said: It has to be REAL data type since the reading is of the form 12345,12. That is not true. It is best to use integers for this type of data. The HMI variables allow for an implied decimal. You simply set it up for the 2 decimal places you need and keep track of where the decimal point is if there are any subsequent calculations. In your example case, be sure you use a 32-bit integer, as the actual number in the register will be 1234512 which is too large for a 16-bit integer. Once you learn and understand using integers with implied decimals you will find that many arithmetic operations in your PLC software will be greatly improved. 1 Quote Link to comment Share on other sites More sharing options...
job517 Posted October 15, 2021 Author Report Share Posted October 15, 2021 @Flex727Thank you I think what you suggested is the right solution Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.