LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert to single precision float

I am using a Modbus driver to obtain measurement data. My measurement device
contains a single precision floating point in a so called pair of holding
registers. When I read the data with Labview I get two 16 bit fields in a
data array. I am new to Labview and I am struggling to reconstruct a proper
single precision value (32 bit) from the two 16 bit data fields. Any hints,

Martien
0 Kudos
Message 1 of 7
(4,481 Views)
There are two functions you should look at in the Advanced >> Data Manipulation palette: Join Numbers and Type Cast.
Join Numbers takes two 16 bits numbers and joins them into one 32 bit number (or two 8 bit into one 16 bit). When you join them, make sure you know which is your high word (or Most Significant Word) and which is your low word (or Least Significant Word). You could also create your 32 bit number by multiplying the high word by 2^16 and adding it to the low word.
If your number is in the IEEE 32 bit floating point format, you then need to Type Cast that number as a single precision number. On your diagram, create a numeric constant, right-click on it and change the Representation to SGL. Wire that constant to the Type input of the Type Cast function an
d wire your new 32 bit number to the X input.
0 Kudos
Message 2 of 7
(4,481 Views)
It sounds like your measurement device is using the IEEE 754 standard for a single precision number. The numbers are obviously split into two fields but actually represent one 32 bit number. If you look at the binary representation of that 32 bit number, the first bit is the sign of the number (0 positive, 1 negative), the next 8 bits represent the exponent of the number, and the last 23 bits represent the mantissa of the number. I hope this helps.

Regards,

Steve
Message 3 of 7
(4,481 Views)
The Type Cast function (in the Advanced >> Data Manipulation palette) takes care of this for you, so you don't have to parse the 32 bit number into fields and do the math to get the floating point number. You just put in the 32 bit number, wire the Type input to a LabView numeric constant represented as Single, and you get out the floating point number.
0 Kudos
Message 4 of 7
(4,481 Views)
You're right. I just tried that and it worked like a charm. Oh well, I guess a little extra info doesn't hurt.

Regards,

Steve.
0 Kudos
Message 5 of 7
(4,481 Views)
Thanks Al and Steve,

I tested the procedure given by Al and it works perfectly. Thanks very much
for your help, and the extra info of Steve certain did not hurt. On the
contrary, I appreciate it in order to understand better what is actually
happening when reassembling the floating points.

Kindest regards,

Martien


"Steve W." wrote in message
news:50650000000500000031C50000-1042324653000@exchange.ni.com...
> You're right. I just tried that and it worked like a charm. Oh well, I
> guess a little extra info doesn't hurt.
>
> Regards,
>
> Steve.
0 Kudos
Message 6 of 7
(4,481 Views)
I agree with Steve here. I have run into similar situations with different IEEE standards, and multiple times it came down to this problem.
J.R. Allen
0 Kudos
Message 7 of 7
(4,481 Views)