Sign in to follow this  
Followers 0
mjrx

How do I move a float file to 2 integers?

10 posts in this topic

How would I move a floating point variable, say F8:0 into two consecutive integers, say N15:0 & N15:1 on a Micrologix 1500? I think the COP instruction may work on SLC's, but ML's won't allow different source & destination.

Share this post


Link to post
Share on other sites
Try the Copy Word (CPW) instruction. This instruction is specific to the MicroLogix 1100/1200/1400/1500 and is most often used with Function Files. It should copy the 32-bit contents of a single Float element into two consecutive Integer elements.

Share this post


Link to post
Share on other sites
Just use two MOV instructions. Or if you have it, you might be able to use FLL. COP (copy) is intended to block copy a consecutive series of values from one block to another. Depending on the vintage of the PLC, it may or may not do type conversion.

Share this post


Link to post
Share on other sites
Thanks for all the responses. I don't see how to do it with MOV instructions - what I need to do is have the high word of the floating point element go into 1 16 bit data space (N7:0) and the low order word of the floating point element go into the second 16 bit data space (N7:1).

Share this post


Link to post
Share on other sites
Have you tried Ken's CPW recommendation? This will move the bit patterns which make up the floating point number. If, instead, you mean moving the integer portion of a floating point number to one integer and some representation of the fractional part to another loacation then that is a very different process. Edited by b_carlton

Share this post


Link to post
Share on other sites
Yes, I need to move the bit representation of the 32 bit float into two consecutive 16 bit registers. These integers will then be available to a host PLC via Modbus (the ML1500's are configured as Modbus slaves). The master (Mits Q) will read this block of integers and re-create the floating point values. I think the CPW will work, however I do not have a ML1500 right now, I need to make the changes in the field so I am just trying to see what my options are. Thanks again.

Share this post


Link to post
Share on other sites
The CPW will definitely work. Note that the Length parameter refers to the destination element, so set the Length to 2 to get all 32 bits of a single float into two consecutive integers. For more than one consecutive floating point, set the Length to twice the number of floats you want copied (since they are twice the size, in bits, of the destination element type). Paul Edited by OkiePC

Share this post


Link to post
Share on other sites
In a program for a micrologix 1400 I have tried the CPW from the floating point to a long integer file with, on the first trial, a length of 2, and then on the second trial, a length of 1. RSLogix 500 diidn't like either way. I've attached the program. The problems are on rungs 185 and 186. Thanks in advance, Mark AUTOTACKER 9pin.RSS

Share this post


Link to post
Share on other sites
You used a "Long" data type instead of an "Integer" data type for the destination. http://www.plctalk.net/qanda/showthread.php?t=81629&highlight=cpw

Share this post


Link to post
Share on other sites
I need floating point or long word storage to hold the results of my calculations. I tried using integer N7 files and that didn't work either. The AIC instruction won't take floating point as a source. How can I get my position value into an ASCII message to my servo? Is there any other way to convert it back? Thanks, Mark

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