Sign in to follow this  
Followers 0
Spedley

AB's round to nearest decision

11 posts in this topic

I personaly think that AB made a mistake when they decided to round results to the nearest value. What do you think?

Share this post


Link to post
Share on other sites
There are others would say its a mistake to truncate.

Share this post


Link to post
Share on other sites
Personally I would rather it round than truncate. It is rare I need to truncate something but use the rounding feature all the time Now a truncate instruction for the Micrologix would be nice

Share this post


Link to post
Share on other sites
You can get a truncate (and a remainder if you wish) by using the DDV and the math reigster. Kind of a pain, but it is do-able.

Share this post


Link to post
Share on other sites
Yes but Controllogix has spoiled me

Share this post


Link to post
Share on other sites
The rounding part is OK. But a TRUNCATE function would have been very useful.This would have given the programmer more options!!!.And why would AB not include that in RSLogix500?Since many other PLCs have truncate instruction in their programming software.

Share this post


Link to post
Share on other sites
I agree with the OP that Rockwell screwed up but truncate is not the answer. Truncate is sign dependent. It drops fractions so the result is alway closer to 0. This means one needs to check the sign to determine if a -0.5 or +0.5 needs to be added before truncating. I think what is really wanted is a floor function. A floor function returns the next most negative integer. That way one can just add .5 to round no matter if the sign is negative or not.

Share this post


Link to post
Share on other sites
What is the logic behind truncating data? How does this affect your program? Ive been programming for a while, and never needed to truncate data.

Share this post


Link to post
Share on other sites
Rounding takes place whenever a floating point number is copied to a integer file. Are you telling us you have never converted a floating point number to an integer? I have seen a few threads where someone has wanted to round numbers to 1,2 or 3 decimal places. I believe this should be done in the HMI, not the PLC. BTW, many embedded systems use the GCC library. We have found that many of the floating point funcitons in the library are flawed in that they do not provide values such as sin() to more than 4 decinal places. I know that even fewer people actually using anything but add, sub, mult and div but I thought everyone should know. It makes no difference if the processor can do 64 bit floating point if the library is flawed.

Share this post


Link to post
Share on other sites
Truncation is mostly used when you are using integers. It is used when you when you want to process part of a number rather than the whole, i.e. using 32-bit maths on a 16-bit processor. or simliarly when converting integers to strings.e.g. to convert 456 to a string (assuming the processor does not have a [pseudo-]instruction to do it. (456 DIV 100) MOD 10 = 4, then add the ASCII value of zero (i.e. 48) and you get 52 which would output as '4' (456 DIV 10) MOD 10 = 5 ... would output as '5' (456 DIV 1) MOD 10 = 6 ... would output as '6' without truncation (with rounding) you would get (456 DIV 100 =rounded upto 5) MOD 10 = 5 ... would output as '5' (456 DIV 10 =rounded upto 6) MOD 10 = 6 ... would output as '6' (456 DIV 1=6) MOD 10 = 6 ... would output as '6' Does that make sense? Edited by Spedley

Share this post


Link to post
Share on other sites
I see what ur saying, but i have never come across an application where i would have to do such a thing. Thanks for the info guys

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0