RE- compose IEEE Floating Point Number

Scorpip

Member
Join Date
Aug 2004
Posts
15
I am transferring data ASCII Modbus though an Allen Bradley Point I/O Rs232 module.
I can query the data and load my data tables with the information.This work well but I am sure there is an easier way. But this is the route I have to follow

The problem is converting the data into floating points. I understand the process but I think there has to be an easier way. Here is what I have.

I am using PLC 5

I receive the data into the integer files. For example sake, let say I get them in order…
Reading it in ASCII
N7:0 – 4A
N7:1 – D0
N7:2 – 5E
N7:3 – 08
Reading in Decimal right from the tables
N7:0 – 13377
N7:1 – 17456
N7:2 – 13637
N7:3 – 12344


My first problem is 4A = 74 not 13377. So I am assuming there is some data somehow truncated on the ASCII – Hex data? Not sure why or what to do with it.

The number I am trying to get is 6827780

If I take this number (Float point) and copy it to an integer file, I will get two integers.
19152 and 24072. This is easily understood.


I know that if you take the following and copy them in to a floating point you will get the proper number back 6827780. Again easy, peasie…


4AD0 = 19152
and
5E08 = 24072
But looking at the data I am getting, it is stored in 2 byte data chunks 4A and D0 and 5E and 08.


How can I put these back together to attain the correct floating point value?
If the data in the tables actually where 4A, I could bit shift it and add the second but for some reason this will not work.

I am thinking I missing the point and over seeing something obvious. Anyone have a minute, I would appreciate some feedback.


This is a Sigma Water Meter. Communicates ASCII Modbus via wireless to a 1734-RS232 Point I/O Module then DeviceNet into my PLC.

I tried to get the system to transfer 4 byte chucks of info which would be nice but it is not happening.

Thanks for anything anyone has to offer!


Here is the old fashion way
4AD05E08 (hex)
01001010 11010000 01011110 00001000 (binary)
The Sign of the mantissa (and therefore the number) is 0 which represents a positive value.
The Exponent is 10010101 (binary) or 149 decimal.
The exponent field is represented in excess 127 so the exponent value is 22

The Mantissa is 10100000101111000001000 binary
with the implied leading 1, the mantissa is (1).A0BC10 (hex)

The floating point representation is therefore +1.62786961 times 2 to the 22



Here is a great Website for some detail for anyone.

http://www.markworld.com/showfloat.html



Scorpio
 
Last edited:
The 'big thing' that you're overlooking is that the Modbus data is encoded as ASCII, not as hexadecimal, BCD, or 2's Complement Binary.

In ASCII code, '4A' is two 8-bit characters. '4' in ASCII equals 34 hex, which equals 52 decimal. Capital 'A' in ASCII equals 41 hex, which equals 65 decimal.

Have a look at an ASCII chart for these equivalents: http://www.lookuptable.com

While the PLC-5 does have a "String-to-Integer" instruction (ACI), it doesn't have a "ASCII HEX String-to-Integer" instruction.

So, you're going to have to get a little bit inventive.

(continued)
 
Hmmmm.... that makes a bit more sence.... I look forward to your continuation...

I gotta get a processor here at home :)

Thx
 
I've been messing around with BTD's and FOR/NEXT loops for an hour now... see what this Forum does to us!?!

I have a PLC-5 Emulator installed on my laptop, so this sort of thing is easy.

I got the data to parse out and convert, now I just need to make it go back together in the right order.
 
I got this to work in 10 rungs:

SOR BST BTD #N7:0 8 N10:0 0 8 NXB BTD #N7:0 0 N10:1 0 8 NXB BTD #N7:1 8 N10:2 0 8 NXB BTD #N7:1 0 N10:3 0 8 BND EOR SOR BST BTD #N7:2 8 N10:4 0 8 NXB BTD #N7:2 0 N10:5 0 8 NXB BTD #N7:3 8 N10:6 0 8 NXB BTD #N7:3 0 N10:7 0 8 BND EOR SOR FOR 1 N11:0 0 7 1 EOR SOR ADD N11:0 8 N11:1 EOR SOR LIM 48 N10:[N11:0] 57 SUB N10:[N11:0] 48 N10:[N11:1] EOR SOR LIM 65 N10:[N11:0] 70 SUB N10:[N11:0] 55 N10:[N11:1] EOR SOR NXT 1 EOR SOR BST BTD #N10:8 0 N10:16 12 4 NXB BTD #N10:9 0 N10:16 8 4 NXB BTD N10:10 0 N10:16 4 4 NXB BTD #N10:11 0 N10:16 0 4 BND EOR SOR BST BTD N10:12 0 N10:17 12 4 NXB BTD N10:13 0 N10:17 8 4 NXB BTD N10:14 0 N10:17 4 4 NXB BTD N10:15 0 N10:17 0 4 BND EOR SOR COP #N10:16 #F8:0 1 EOR SOR END EOR

Copy and paste the above into RSLogix 5 and it will enter a routine that uses N7:0-3 as a source string, works in data file N10:0-19 and N11:0-1 and outputs to F8:0. Call that subroutine once and it will convert your ASCII Hex into a Floating Point number.

I'll comment and post the RSLogix 5 code shortly.
 
Last edited:
Here we go, in RSLogix 5 format.

If you had the chance to do it over again, I'd recommend looking for some DeviceNet product that directly supports Modbus ASCII, like the Western Reserve Controls 1782-JDM (www.wrcakron.com).
 
Ken, I wanted to thank you for the code.. not only was it a help for the project but also help me to understand the process... Good Stuff!!!

I managed to come up with another question pending from this project. I had to add another receiver but instead of doing so with the Devicenet mod and the Rs232, I am tring to use the MMI closer to the area I am workng in. Using VBA in Rsview is the route I have taken on this project and reading data and storing it is no trouble... converting is another issue I am trying to over come

Pulling in the data via Mscomm in VB and parsing it into anything I want to look at is not a problem. I was wondering if there is anyone that has any snippets to take the data for example (hex)4C6EC787 and convert into a floating point in Visual Basic? Which is (62594587)

As always, thanks for any help, logic, web sites, reading etc...
 

Similar Topics

Hi all, Given a variable VAR1 at an address of %R101 is it possible within the PLC program to decompose this so that you can say the address is of...
Replies
12
Views
3,550
Hello Guys, I've got a problem of using RSLogix Data Table Object to write BOOLEAN type of value. For SINT, INT, DINT, I can use following...
Replies
1
Views
4,047
Looking for some explanation/history between North American electrical symbols standards (how they relate, what are the latest, what is the...
Replies
3
Views
1,692
Hello! Long time lurker and gatherer of information - love this forum. I am trying to find some sort of tag naming standard if it exists...
Replies
18
Views
8,394
Back
Top Bottom