2 Word Conversion to Floating Point

M

Thread Starter

Monroe Strike

Hi,

I am receiving a floating point value from a device over DeviceNet. However, the floating point value is split into 2 Integer words.

AB PLC5 example:
F9:0 = MSB Word 0, LSB Word 1

How do I make the MSB and LSB convert to a Float.

Thanks
Monroe Strike
 
use a COPY instruction

Source = MSB integer word (your example, WORD 0 )
Destination = Floating point word
Length = 1

When you copy to floating point from integer (16-bit)it automatically takes two integers to make the 32-bit floating point word
 
A

Anthony Kerstens

If it were modulo 10000, then
F9:0 = 10000*MSB+LSB

The PLC should to the proper conversion to floating point. However, it would do the math in two steps. If you have problems then add a
decimal like this to force it to use floating point:

F9:0 = 10000.0*MSB+LSB
If you still have problems, LSB + 10000.0*MSB.

Anthony Kerstens P.Eng.
 
C

Curt Wuollet

That depends entirely on what you are doing it on.
That would be a library function in most cases.

cww
 
The task at hand:

>> Receiving a floating point value from a device over DeviceNet.
>> However, the floating point value is split into 2 Integer words.
>>
>> AB PLC5 example: F9:0 = MSB Word 0, LSB Word 1
>> How do I make the MSB and LSB convert to a Float.

If the incoming number is a DeviceNet REAL number, it should conform to IEE754's definition of a single-precision floating point number just like the PLC-5 does.

In the PLC-5 floating-point format, the 32 bit data type is comprised of a sign bit (s), eight exponent bits (e), and twenty-three bits of a
normalized mantissa (f).

31 16] [15 0]
[s eeeeeeee fffffff] [ffffffffffffffff]

Because the PLC-5 receives the least-significant word (LSW) first, it puts it first into the data table of the 1771-SDN block transfer. This means
the LSW and MSW are in reverse order from the way we want to put them into the floating point register.

Use two scratch registers to reverse the order of the incoming words

MOV
Src: N10:1
Dst: N100:2

MOV
Src: N10:2
Dst: N100:1

If you wish, you could dispense with those two instructions and just map these words in reverse in the 1771-SDN data table.

Then use the PLC-5 COP (copy) instruction to copy these correctly ordered 16-bit data elements into a single floating point element. Because COP
is a file instruction, use a file length of 2 (for two elements of the source data).

COP
Src: N100:1
Dst: F9:0
Len: 2


This will work if the incoming value is a REAL data type. However, if the incoming number is really a DeviceNet DINT or UDINT double-integer, you have a harder conversion on your hands.

This is just one of the reasons I prefer the ControlLogix for DeviceNet applications. The Five has it's place in heavy-duty and legacy
applications, but I really prefer the Logix platform as a programmer.

Good luck,

Ken Roach
A-B Seattle
 
J

Jerry Baucum

It's interesting how often this comes up.

If you are talking about an A-B PLC-5x communication then the order of the bytes in the words are standard Intel (low/hi) order but the words are in "network" (high/low) order. Thus on an Intel PC to convert a PLC-5x float to a 'C' "float" one must reverse the WORD order and leave
the BYTE order alone. This is true of any of the PLC-5 4 byte entities.

void CnvtPC_Plc5_Float(WORD *to, WORD *from)
{
*to = *(from+1);
*(to+1) = *from;
}

Will work in either direction from PC to PLC-5 or from PLC-5 to PC.

If dealing with a high/low oriented processor then reverse the byte order in each word and leave the word order alone.

void CnvtHILow_Plc5_Float(BYTE *to, BYTE *from)
{
*to = *(from + 1);
*(to+1) = *from;
*(to+2) = *(from+3);
*(to+3) = *(from+2);
}

If your are dealing with PLC-3 floats or non IEEE float representations then 'course it's a bit more involved.

Note: This is not the case with SLC where floats are communicated in standard Intel order.

Jerry

Jerry M Baucum
Bullet Software
3213 Peppertree Pl.
Plano, TX 75074, USA
Tel: (972) 633-9111
Fax: (972) 633-9112
Email: [email protected]
Web: www.bulletsw.com
 
P
It also depends on how the two registers in your device are representing data. I was recently surprised to find out that SLC stepper cards represent data with an MSW of from 0-8338 and an
LSW of from 0-999. This is a lot different that the GE cards we used last... which are a straight 32-bit word.

Paul T
 
M

Mark Fairbaugh

Use a compute block and make your destination Fx:xx

Mark Fairbaugh
PT Newmont Nusa Tenggara
Sr. Process Control Engineer
e-mail: [email protected]
Phone: (62)-370-636-318 Ext. 47948
 
E

Earner, Nicholas

For an AB-PLC5 you need to copy the 2 N words into 1 Float.
ie. COP
Copy File
Source #N7:0
Destination #F9:0
Length 1
This will copy N7:0 (MSB) and N7:1 (LSB) into F9:0.
Regards, Nic Earner
 
S

SHailesh Bangale

How to achieve this functionality in CCW software? Which instruction to use. Please send some reference backup for study.

Shailesh
===================================================================

>The task at hand:

>> Receiving a floating point value from a device over DeviceNet.
>> However, the floating point value is split into 2 Integer words.
>>
>> AB PLC5 example: F9:0 = MSB Word 0, LSB Word 1
>> How do I make the MSB and LSB convert to a Float.

>If the incoming number is a DeviceNet REAL number, it should
>conform to IEE754's definition of a single-precision floating
>point number just like the PLC-5 does.

>In the PLC-5 floating-point format,
>the 32 bit data type is comprised of a sign bit (s), eight
>exponent bits (e), and twenty-three bits of a
>normalized mantissa (f).<pre>
> 31 16] [15 0]
> [s eeeeeeee fffffff] [ffffffffffffffff]</pre>

> Because the PLC-5
>receives the least-significant word (LSW) first, it puts it
>first into the data table of the 1771-SDN block transfer.
>This means the LSW and MSW are in reverse order from the
>way we want to put them into the floating point register.

>Use two scratch registers to reverse the order of the
>incoming words<pre>
> MOV
> Src: N10:1
> Dst: N100:2

> MOV
> Src: N10:2
> Dst: N100:1</pre>
>If you wish, you could dispense with
>those two instructions and just map these words in reverse
>in the 1771-SDN data table.

>Then use the PLC-5 COP (copy)
>instruction to copy these correctly ordered 16-bit data
>elements into a single floating point element. Because COP
>is a file instruction, use a file length of 2 (for two
>elements of the source data).<pre>
> COP
> Src: N100:1
> Dst: F9:0
> Len: 2</pre>
> This will work if the incoming value
>is a REAL data type. However, if the incoming number is
>really a DeviceNet DINT or UDINT double-integer, you have a
>harder conversion on your hands.

> This is just one of the
>reasons I prefer the ControlLogix for DeviceNet
>applications. The Five has it's place in heavy-duty and
>legacy applications, but I really prefer the Logix platform
>as a programmer.

===================================================================
 
Top