Sign in to follow this  
Followers 0
wildswing

How does PLC5 convert single floating point to two integers?

8 posts in this topic

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 Edited by wildswing

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by TWControls

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by Alaric

Share this post


Link to post
Share on other sites
Oh ok, it's magic

Share this post


Link to post
Share on other sites
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. How_floating_point_numbers_are_represented_in_binary.doc

Share this post


Link to post
Share on other sites
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

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