Extracting Floating Point Value from RS458.

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Extracting Floating Point Value from RS458.

Post by Jay Dee »

Hi,
We are looking to use a high accuracy level sensor, it is available with either a 4-20mA Analogue output or an RS485 digital output.
The Taiwanese documentation is limited. However they do say that the Level data is output as a Float on address 0x1007.
I am expecting 4 bytes following the address to be the Float data.

Now...Robbing an explanation from StackExchange by John Bode

"Like signed integer types, the high-order bit indicates sign; 0 indicates a positive value, 1 indicates negative.
The next 8 bits are used for the exponent. Exponents can be positive or negative, but instead of reserving another sign bit, they're encoded such that 10000000 represents 0, so 00000000 represents -128 and 11111111 represents 127.
The remaining bits are used for the significand. Each bit represents a negative power of 2 counting from the left, so:
01101 = 0 * 2-1 + 1 * 2-2 + 1 * 2-3 + 0 * 2-4 + 1 * 2-5
= 0.25 + 0.125 + 0.03125
= 0.40625 "

SO.. to anyone who might have experience of industrial RS485 or Floating point numbers in general... does the above all seem the right approach.
Is there a better way to convert floats?
any help appreciated.
Regards, J.
My alternative is to just get the analogue version put the signal it through a 4-20ma Buffer and into a SPI 16bit precision ADC. :)

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 187 times
Been thanked: 140 times
Contact:

Re: Extracting Floating Point Value from RS458.

Post by petesmart »

Hi jaydee,

This looks very much like an industry based IEEE 754 format....your in luck as I have written a conversion macro for the new dsPIC MIAC in FC7. this shold be transportable across the pic range..

See the MIAC blog article on the Matrix website...there is photo of of a power management device I was controlling via RS485....

I'm traveling at the moment so I will post this to you in the next few days...ping me again if I forget :P

All the best

Pete
sorry about that Chief!

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: Extracting Floating Point Value from RS458.

Post by Jay Dee »

Hi Pete,
Yes that would be excellent if you could post or PM.
I hope if my development budget allows, I'll be getting two sensors, analogue to get everything up and running, then one with digital output to work on the RS458 and extracting the float values later. Hopefully finding those elusive last few bits of precision.
Regards, J.

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 187 times
Been thanked: 140 times
Contact:

Re: Extracting Floating Point Value from RS458.

Post by petesmart »

Hi JayDee,

Just got back from US.... Here is promised the IEEE 754 macro

Note that the .return provide you with a floating point number...

Also check out the properties – there are a number of options to turn on/off test data and displaying the raw captured RS-485 data (second macro attached)

All you need to do is to point your RS-485 data into Modbus_byte[8] array – the macro will take it from here

See how you get on with it

All the best

Pete
Attachments
display_MODBUS_ouput.FCM
(3.6 KiB) Downloaded 284 times
IEEE754.FCM
(8.03 KiB) Downloaded 313 times
sorry about that Chief!

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: Extracting Floating Point Value from RS458.

Post by Jay Dee »

Thanks Pete, Great Stuff.
On my work travels as well, just finishing in China and back to UK for a few days so hope to have a proper look then. Thanks.

Post Reply