RSLogix 5000 Truncate

dwalters65

Member
Join Date
Mar 2013
Location
Ohio
Posts
3
I'm currently working on a project that requires me to use a compute. I'm trying to truncate the first part of the equation and then divide by 1000. I was wondering will this work for the expression? (TRN(ExxxxxxLoad_Dx_aoi*1000))/1000
Any help or ideas would be much appreciated. Thanks!
 
Welcome to the forum.

I take it you are trying to truncate a real to three decimal places. On the surface one would think that should to the trick, but you need to understand how floating point numbers are stored in a computer.

So first, I have to ask why you are truncating and then dividing by 1000? Because of the way a real number is stored in a computer with the IEEE-754 format, you aren't going gain anything by doing that. Some numbers (anything ending with a .xx1 or .xx2 and quite a few others) won't stay at three digits when you save them back to the real anyways because they can't be represented exactly, so 5.432 becomes 5.4319997 anyways.

If you can explain what you are trying to accomplish then maybe we can help you find a solution that will work. IEEE-754 float problems is a common topic here and there are several forum members who can help.
 
Last edited:
You could always multiply by a 1000 using a MUL. A = 1.23456 B = 1000 C = 1234. A is a real while C is a dint. Then use a DIV and divide by a 1000 with A being your previous result and this time C (1.234) being a real. You could also use 2 compute statements.
 
Well as far as what i'm trying to do. I'm trying to monitor a motors position to the thousandth. They're currently using real values and yes if i don't use a dint, it will not be exact. But if i truncate a real multiplied by 1000 then divide by 1000, the destination number should basically round the number below the truncated number. if that makes any since. example: 16.908265 * 1000= 16908.265 then truncated to 16908 then / 1000 = back to a real value of 16.908000. So it's below that number at maybe 16.907989. This is what i need.

Really i'm developing a routine that manipulates and must work around standards that have been set in the drive control routines. Where the drive control routines use real values by standard.

I appreciate your quick response and am still interested in different ways to accomplish the same. Thanks!
 
Why do you care what the representation in the PLC is?
Do you just want to arbitrarily add complexity and reduce accuracy?
Or are you trying to display the value on an HMI showing only 3 decimal places?

If it is the latter, then do the formatting on the HMI, not the PLC.
 
We are constantly monitoring position to 6 decimals .000001 and there's no deadband. Just with noise alone, it can't maintain that kind of position accuracy. So my thought was to monitor to the thousandth. The drive motion to the position is in a locked aoi which writes to a real value. This limits my capabilities to make the changes that are really needed. I'm new to this forum and am learning that I should have better described my dilemna. Thanks all for your patience.
 
You will fail if you try to limit it to three decimals because EVERY SINGLE TIME your equation answer is one of the ininite number of reals that cannot be EXCATLY represented in the IEEE-754 float format then you'll get more than three digits.

It has been my experience that most people have to see for themselves in order to be convinced. Fortunately there is a cool online tool to help you actually see how it works. Go to http://babbage.cs.qc.edu/IEEE-754.old/Decimal.html to see how a floating point number will look in binary. Punch in a number. Click the NOT ROUNDED button so you can see how it will be in computer memory. Try a few dozen numbers with three decimal places or less. Look under Single Precision to see how the float is stored in binary in computer memory, then see what its actual decimal value is. You'll very quickly see that most floats are not represented exactly and how trying to limit it to three decimal points is futile. Try the number you used above, 16.908. That is another value that CANNOT be represented exactly in an IEEE-754 floating point format. Type it in and you'll see that it becomes 16.907999 in computer memory, so if you truncate it and then divide by 1000 it goes right back. Don't worry, you are not the first programmer to be vexed by the limitations of doing floating point numbers in a computer. Your computer on your desktop has very sophisticated software to recognize and convert the number to a rounded string for display on your computer screen. But when you do computations you are still using the number that is stored in memory, not the string of characters displayed on your screen. There is a link on that page to reference materials if you want to learn more.

The way to deal with the problem is to choose different units so that you can use integers. Instead of measuring inches you may want to make your primary unit be thousandths of an inch and use a DINT instead of a real.
 
Last edited:
Waterbath Project

Hey guys,

I have this project for waterbath flow alarm, can someone help me how to do a ladder program in rslogix5000. Here is the condition, if my waterbath flow drops from spec (eg 50lpm), then an initial alarm will be generated telling me that it is low/oos. And if this low alarm will not clear within 15 minutes, then my product on the water bath will be scrapped. And the alarm timer/counter will only be cleared if the alarm is cleared for 15 minutes. Thanks
 
Hey guys,

I have this project for waterbath flow alarm, can someone help me how to do a ladder program in rslogix5000. Here is the condition, if my waterbath flow drops from spec (eg 50lpm), then an initial alarm will be generated telling me that it is low/oos. And if this low alarm will not clear within 15 minutes, then my product on the water bath will be scrapped. And the alarm timer/counter will only be cleared if the alarm is cleared for 15 minutes. Thanks
Please post a new thread as this is an old thread and not related to your question.

Also, post your work so far and we'll help along. We won't do your job or homework for you.
 
Hello, I have google my question without much luck. I am using the FGEN and trying to find out how to control the number of decimal places that is output since one of my outputs was to 7 decimal places causing my test to fail. I need the I/O to be <= 2 decimal places but cannot find out in the FGEN that I can control the number of decimal places. Has anyone ever encountered this before? Thanks in advance for help.
 

Similar Topics

Hello, I am trying to read a barcode scanner input using a cognex dataman 280 barcode reader, store it another string, the compare with another...
Replies
0
Views
15
Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
164
I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
600
First off, I'm a hobbyist-level programmer, and this program isn't controlling anything anything that could even remotely be considered "life...
Replies
18
Views
534
Back
Top Bottom