LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modbus: float to two words

Solved!
Go to solution
Solution
Accepted by topic author _Faust

 


@_Faust wrote:

Yes that did the trick, but why isnt the 16 bit type cast enough to accurately transform the number? Its only 4 digits long.

 

I used the word typecast because the modbus library takes words, but that isnt necessary?

 


FYI, a SGL is stored as sign bit + 8 bit exponent + 23-bit significand.  You convert to a floating point by finding significand * 2^exponent (with some bit fiddling).  When you lop off the last 16 bits, you are left with a 7-bit significand, the smallest significand you can represent is 1/2^7 or 1/128.  For your value of 12.33, the exponent is 3, so the smallest value you can represent here is 1/128*2^3 = 1/16, so 12.3125 is your original value rounded down to the nearest multiple of 1/16.

 

Message 11 of 12
(1,685 Views)

Thank you all for your expert knowledge!

0 Kudos
Message 12 of 12
(1,672 Views)