Understanding PLC handling of division calculations with DINT data types in Logix controller

Question:

I have a structured text routine in a Logix controller with an expression that involves multiplying and dividing several DINT data type variables. The calculation always results in a number in the thousands, and decimal accuracy is not crucial. My concern lies in the fact that one of the variables, Integer5, will always be greater than Integer4. This means that the initial division calculation, Integer4 / Integer5, will yield a number less than 1. To ensure the calculation is done correctly, I need to know how the PLC handles truncation or rounding in such scenarios. Can someone direct me to the relevant documentation for a better understanding of this process? Thanks!

Top Replies

Are you familiar with the concept of zero division in programming? To avoid this issue, ensure that the result of dividing Integer4 by Integer5 is not zero. It is advisable to use a floating point data type for the entire calculation. If the decimal part of the result is not necessary, you can round it at the end of the calculation.

In this calculation, it is essential that none of the values are zero. While I am open to using floating point if necessary, I would like clarification on whether it is required.

If your calculation consistently results in zero, consider using floating point numbers to address the issue. Alternatively, break down the calculation into smaller steps to identify and troubleshoot any errors. This approach can help pinpoint where exactly the calculation is failing.

In order to understand how calculations are performed in PLCs, it is important to refer to the relevant documentation. Without specifying the exact make and model of the PLC, it can be challenging to point to the correct manual. The Logix manual can be a helpful resource, as well as the IEC-61131 standard which covers integer division behavior. To determine the behavior of the expression in question, it may be necessary to empirically test by inputting various values into the PLC. Care should be taken as this could potentially cause processor faults and PLC halts. It is important to note that in computer programming languages, a divide operation with two integers typically returns an integer result with any remainder discarded. This can lead to divide-by-0 errors if the divisor is 0. Some PLCs may round the result, while others may not. To prevent overflow in calculations, it may be beneficial to convert the arguments to floating-point numbers and then back to integers. This approach can help ensure accurate results without the risk of overflow.

The calculation in question requires values other than zero to be utilized. While floating point may be necessary, clarification is sought regarding its use. When Integer5 is double the size of Integer4, the quotient of Integer4 divided by Integer5 will be rounded down to zero. Each aspect of the equation must be computed with integer rounding and truncation. It is advisable to convert integers to REALs, conduct calculations using floating point arithmetic, and then convert the result back to Integer afterwards. It is important to note that REALs come with their own set of limitations. Take the time to study different data types and learn how to select and manipulate them effectively.

In PLCs, when you're dealing with integer division where the divisor is larger than the dividend (such as Integer4/Integer5 in your case) the result is truncated towards zero. So there won't be any rounding, rather it lops off any digits to the right of the decimal point. I'd specifically recommend reviewing the Logix 5000 Controllers General Instructions Reference Manual, it has a portion detailing how arithmetic operators function in these situations. It should provide the exact insight and details you're looking for.

From my experience working with Logix controllers, you're right to be concerned about rounding values during calculation. PLCs typically use truncation not rounding when performing integer division. This means, when you perform Integer4/Integer5, the result will almost always be zero if Integer4 is less than Integer5, as you've stated. Instead, you should convert your integers to real data type before the division operation to preserve decimal accuracy. You can then convert it back to DINT if necessary. Check out the Rockwell Automation website, they provide extensive guidelines on such data type manipulations in their documentation section.

You've raised a good point about PLC numeric operations. Typically, when dealing with integer division in PLCs, the result is an integer and the fractional part is truncated (not rounded). This means that if Integer4 / Integer5 is less than one, the PLC logic will consider the result to be zero. To avoid this, you can consider changing the sequence of your calculations to multiply before dividing, or cast your variables to REAL data type prior to the division. However, the exact operations and results may vary based on the PLC model and programming conventions. I recommend consulting the precise PLC model's instructions set handbook for thorough understanding. Rockwell Automation's website could be a good starting point as they have a comprehensive database of manuals for different models.

Great question! In PLCs, especially with structured text in Logix controllers, division between two integers usually results in an integer as well, which means any fractional part gets truncated, not rounded. This can lead to unexpected results if you're not accounting for that. If you're looking for documentation, check out the Rockwell Automation knowledge base or the manual for your specific Logix versionβ€”it usually has a section on data types and arithmetic operations that covers how truncation and casting are handled. You might also want to consider using a real (floating point) data type for calculations if you ever need more precision in the future.

It's a good question! In most PLCs, when you divide two integers and the result is less than 1, the value is typically truncated to 0. So in your case, Integer4 divided by Integer5 would just give you 0 unless you convert one of those integers to a floating-point or real number before the division. This would allow you to retain a fraction rather than losing it entirely in the truncation. For documentation, I recommend checking out the user manual for your specific Logix controller, as they usually have a section on data types and arithmetic operations that should clarify how these operations are handled in your environment.

It sounds like you're digging into some important aspects of handling calculations in your Logix controller! In your case, when you divide Integer4 by Integer5, the result will indeed truncate to zero since you're working with integers and anything less than 1 won't represent a decimal in this format. For your situation, you might want to consider casting the variables to a floating-point type before performing the division, which can help you avoid the truncation issue. You can find more detailed information about data type handling in the Logix 5000 documentation, especially in the sections regarding arithmetic functions and data type conversions. Good luck with your routine!

More Replies β†’

Streamline Your Asset Management
See How Oxmaint Works!!

βœ…   Work Order Management

βœ…   Asset Tracking

βœ…   Preventive Maintenance

βœ…   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: FAQs:

Answer: 1. How does a Logix controller handle division calculations with DINT data types when one variable is greater than the other? - Answer: When dividing two DINT data type variables where one is greater than the other, the result will be truncated to an integer value, discarding any decimal places.

FAQ: 2. Is decimal accuracy important in division calculations involving DINT data types in a Logix controller?

Answer: - Answer: In scenarios where DINT variables are being divided in a Logix controller, decimal accuracy is not crucial as the result will be an integer value.

FAQ: 3. Where can I find documentation to better understand how a PLC handles truncation or rounding in division calculations?

Answer: - Answer: You can refer to the relevant documentation provided by the manufacturer of the Logix controller for detailed information on how division calculations are handled, especially in cases where truncation or rounding may occur.

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  β†’