Help - Search - Members - Calendar
Full Version: How does PLC5 convert single floating point to two integers?
Forums.MrPLC.com > PLCs and Supporting Devices > Allen Bradley
wildswing
Just curious. Does anyone know the specifics of how the PLC5 converts a single floating point to two integers and back using the COP command? Is it some standard formula?

From floating point to integer: SOR COP #F8:0 #N7:0 2 EOR
and from integer back to floating point: SOR COP #N7:0 #F8:1 1 EOR
panic mode
there is NO conversion at all. it's just bit-by-bit copy but the controller
interprets it differently because it's different data table.

TWControls
Can you be a little more specific. Are you having problems with the data changing during this copy command or what?

I get the feeling your data is varying. You can use a MOV instruction instead of the copy instruction. This will put the proper value in the integer minus the decimal. But if the floating value goes about 32767 is will cause a math overflow. I don't think the copy instruction causes one but it doesn't put the proper values in either.
wildswing
QUOTE(TWControls @ Apr 10 2006, 11:00 AM) [snapback]31672[/snapback]
Can you be a little more specific. Are you having problems with the data changing during this copy command or what?

I get the feeling your data is varying. You can use a MOV instruction instead of the copy instruction. This will put the proper value in the integer minus the decimal. But if the floating value goes about 32767 is will cause a math overflow. I don't think the copy instruction causes one but it doesn't put the proper values in either.


No, not having any problems. I was just curious. I use the COP function to disassemble and reassemble floating point numbers into and out of block tranfer reads and writes. I was just curious what the processor does when it executes the copy.
Alaric
QUOTE(TWControls @ Apr 10 2006, 11:00 AM) [snapback]31672[/snapback]
...I don't think the copy instruction causes one but it doesn't put the proper values in either.


That all depends on what you mean by proper values. COP is an exact copy from four bytes of memory in one location to four bytes of memory in another location. The bit image is exactly the same in both locations. Whether or not it looks the same is simply a matter of interpretation - its still the exact bit pattern.

There are times when a COP is the proper instruction to use, such as when one is attempting to send/read floating point data using serial communications.



If your intent is to split a floating point number into integer/fraction components where XXX.YYY is split into XXX and YYY then see this technote:

http://domino.automation.rockwell.com/appl...F1?OpenDocument



Otherwise see the links I posted on your other post in the PLCS.net forum.
TWControls
Oh ok, it's magic dancered.gif
ratcliffe_ic
See the following note for details of the A-B representation of a floating point number in two integers, I spent ages trying to suss this out in the bar at Heathrow waiting for a plane and it drove me mad, luckily the drink eventually took my mind off the problem.
I then found this on the A-B website.

Alaric
QUOTE(ratcliffe_ic @ Apr 10 2006, 01:56 PM) [snapback]31692[/snapback]
See the following note for details of the A-B representation of a floating point number in two integers, I spent ages trying to suss this out in the bar at Heathrow waiting for a plane and it drove me mad, luckily the drink eventually took my mind off the problem.
I then found this on the A-B website.



ratcliffe - Here is a link to a useful tool. Its a web application that shows you how both single and double precision floating point numbers are represented in computers. You can enter any floating point number and it will show it in binary and also break down how the exponent and mantissa are stored.
http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html

You might also want to take a look at this thread which deals with converting a double precision float stored as four integers into a single precison float in a PLC - following the logic gives a good breakdown of how floats are stored. http://www.plctalk.net/qanda/showthread.php?t=20575




This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.