Float to 2 integers (AB N registers)

jimtech67

Member
Join Date
Jun 2002
Location
New Jersey
Posts
505
I need some help
I am using a SLC 500 504

I want to convert a large floating point number (F register) to 2 integers ( 2 N registers).


Example


[font=&quot]F9:10 = 2,345,765 convert to
N7:2 will be most significant word and
N7:1 will be most least significant word

I need to send servo index position to AB ultra 100 and you must send this info in separate words O:12.3 LSW
[/font][font=&quot] O:12.4 MSW [/font]
[font=&quot]
Thanks

GO JETS


[/font]
 
I assume you mean you want to distribute the floats bit pattern across two integer locations. Use the copy command (COP) to do this.

COP(#F9:10, #N7:1, 2)
where F9:10 is the source, N7:1 is the destination and 2 is the length.

Keith
 
The file attached has been lifted from a working PLC5 project using 1771-QB modules that I think have the same double integer format. It has been proven accurate over all positive and negative values. It is intended to convert multiple values at the same time.

I just cut out the relevant PLC5 subroutine and pasted it into RSLogix500, and I haven't checked it for completness so if you have any questions get back to us. Cheers
 
First you need to define the range. Second, since integers don't include decimal places you will have to have implied decimal places within one or both of the integers. You need to define fixed number of decimal places in your F.
 
We do something similar to get Floats back and forth to an S-Class motion controller. We simply use the COPy instruction. Each Float is copied to two consecutive integer locations.
sample2.jpg


Paul C.
 
OK I could use a lesson/refresher on this subject.

I thought the COP instruction would place zero in an integer file is the number was less than 1.

I forget, its been too long but doesnt AB place the floating point numbers in separate words?

I have code for doing a conversion that was originally for displaying the numbers on a PV. In this example it places the number to the left of the decimal in N7:0 and the value to the right of the decimal in N7:1. As was mentioned the factoring will depend on the number of decimal places involved.
 
Ron-

In some cases a device needs to have a number in IEEE floating point format (which is what the float data type in the AB plcs) but will only allow data transfer through integer data types. An IEEE single precision float is a 32-bit quantity. What you can do is take a float and copy it into 2 consecutive integer values. A COP will do a direct byte for byte transfer between memory locations. By contrast a MOV will do a data type conversion. This is where your point about a zero in the integer comes in. A MOV will round the float to the closest integer.
If you COP a float to two integers the float bit pattern is preserved. You end up with two consecutive integers that don't appear to make any sense. They will only make sense again when they are 'recombined' (I know that's abad term but I can't think of any other) into a single 32-bit quantity.

I hope this helps.
Keith
 
Ok Keith let me make sure I understand this fully. I think I tried using the COP deal and it didnt work where MSW and LSW were involved.

COP will do a bit for bit copy but when moved to the integers files the numbers are "different"... ie 123.123 doesnt come out N7:0=123 and N7:1=123.

I "got" or had to use the above formula because of issues I dont fully remember now. It converted the numeric values to right and left of the decimal place so they could be used for outputs like jimtech was asking for.

I need to setup something a do test to see what happens, its been too long.
 
AB has a tech note on this on their web site.
http://domino.automation.rockwell.com/applications/kb/RAKB.nsf/0/C9B5EA04DF66D67B85256AFB006AAE6C?OpenDocument

Here is a tech note on how floating point numbers are represented in a computer.
http://domino.automation.rockwell.com/applications/kb/RAKB.nsf/0/85C2838CBFC456D285256AFB00695031?OpenDocument

This isn't directly relevant, but its something to consider if you convert back to floating point. While it deals with block transfers, the twos compliment data storage of the AB plcs is important to account for.
http://domino.automation.rockwell.com/applications/kb/RAKB.nsf/0/C9B5EA04DF66D67B85256AFB006AAE6C?OpenDocument
 
Last edited:
Ron-

You are correct. COP doesn't break the float into it's two halves; left and right of the decimal point. It just copies the bit pattern from one memory location to another.
One thing to keep in mind is that the IEEE float format isn't a formatted integer, like XXXXX.YYYYY. It is a combination of a base number and an exponent that defines a power of 2. So there is some stuff inferred in the format that the processor needs to know to make sense out of the bit pattern.

The link Alaric posted is a good overall description of the IEEE format.

Back to jimtech67's original post. Does he need a formatted integer or does he need an IEEE float?

Keith
 
Hopefully jim will come back and clarify things. I think it may be possible that he is using an Ultra 100 with DNET.
 
Overflow?

jimtech67 said:
Example


[font=&quot]F9:10 = 2,345,765 convert to
N7:2 will be most significant word and
N7:1 will be most least significant word
[/font][font=&quot]
[/font]

In this example, wouldn't the 2,345,765 number exceed the size of the integer N7?

RSLogix Help said:
If you use an integer data type, the processor rounds the final value of a mathematical operation before storing the final result. The processor rounds to the nearest whole number. The processor rounds values of 0.5 through 0.9 up to the next whole number; the processor rounds values of 0.1 through 0.4 down to the closest whole number.

If this value is greater than 32,767 or less than -32768, the overflow status bit is set.

© 1997 Rockwell Software Inc.

Help me understand the difference...
 
Daniel
The copy instruction is not a mathematical instruction...It just copies the 32 bits of the float to the 32 bits of two consecutive integers. If the destination words are integers, the length should be set to two. In this example, when I had the length set to one, I got the first half of the float bit pattern in the first N word only. I don't know if this is what the Ultra drive needs. He should be able to test it and go online using ultramaster to see if the results are correct.
Sample3.jpg
 
In this example, wouldn't the 2,345,765 number exceed the size of the integer N7?

That was another reason I was hoping jim would return and clarify. I was originally thinking of floating point always being a number with a decimal place. My example converts the decimal part to an integer file. Originally I thought it read 2,345.765...gotta get new glasses

After rereading what he originally stated:
I want to convert a large floating point number (F register) to 2 integers ( 2 N registers).
I think jim wants to take the 2,345,765 and make 2 integers file that hold 5,765 and 234. This sounds like a high/low byte thing which is another reason I suspect DNET is involved.

Jim are you out there???
 

Similar Topics

Hi, I am using a Phoenix Contact PLC and trying to use it to write a Floating point over Modbus. To do this I need to convert it to two 16 bit...
Replies
24
Views
6,786
I have a MicroLogix 1400 that I am using to communicate with Micro Motion Coriolis meter. I wrote some simple logic that grabs the temp via Modbus...
Replies
22
Views
8,373
Hello, I have a (hope) simple problem with Logix500 (PLC is emulated with Emulate500) interacting with a VB6 program. When I write in a Float...
Replies
10
Views
2,309
I have two integers in Dec. 16169 and -30892. They get moved to a float and displayed. I am wanting to double check the value to expect. I...
Replies
11
Views
3,852
I am receiving data from a controller that is sending out floats or 32 bit words over devicenet to my 5/05 processor. The devicenet is mapped to M...
Replies
3
Views
2,195
Back
Top Bottom