wlindberg86 (Customer) asked a question.

16 Bit Float - Raw Value To Usable Value

I have a Modbus device that I am pulling data from. This device has mostly identical sensors on it that use 5 Modbus addresses each. In this example, I'm pulling data from address 17 which is the temperature in degrees Celsius. According to the device manual, that register is a 16 bit float. The value i get back is one that i fully expected to see (according to the manufacturer). If i take that number and convert it to binary, and input those numbers into an excel spreadsheet, it does some math and returns an actual value in degrees Celsius.. great! All good...

 

Except that's excel... and not the PLC, and for the life of me I cannot seem to get anywhere with this value. I took the raw value from the sensor, and did a CPD instruction (tried this both as a copy value AND copy binary) so that i could break out the individual bits and hopefully get an actual value of either 0 or 1 but it seems that I am missing something, since even though its "value" is 0 or 1, its still not an actual value.

 

-- So the value I am getting in this screenshot is 19991

-- Converted to binary that is 0100 1110 0001 0111

-- Converted to the temperature value is 24.359375°C

 

I'm lost as to where to go from here. Essentially, I need to break out the individual bits in specific groups, do some math between them, and then get a usable value. Screenshots attached and i can upload the program as well.

 

Thank you for any help!!!Screenshot 2024-08-26 081253Screenshot 2024-08-26 075933Screenshot 2024-08-26 071718


  • Durallymax (Customer)

    You have everything you need, it is a half precision IEEE 754 floating-point number. You'll need to map the bits as shown in your picture to calculate the biased exponent and significand, then perform the math as shown in your picture.Screenshot 2024-08-26 102139 

    Expand Post
    • wlindberg86 (Customer)

      thank you so much!

       

      maybe im missing something else... but there's an array needed for "ExpArray" and "SigArray"?

      • Durallymax (Customer)

        Many ways to do it. You need to perform the math bit by bit, Psuite does not allow pointer type access to bit-of-word so it's easier to map them into an array of bools, then loop through to perform the math.

         

        You could just as easily do it with 15 rungs with an NO contact and their own math block

      • kewakl (Customer)

        As @Durallymax already explained, the arrays can be iterated (FOR LOOP). individual bits cannot.

         

        Oh, thanks for the puzzle! 😊

    • kewakl (Customer)

      I did pretty much what you did, except I packed the exponent bits into a numeric, instead of calculating.

      But, like you said, "Many ways to do it."

      • Durallymax (Customer)

        Just looked back at the program I had for doing 32bit and did it that way as well. Brain changed it's mind for 16bit. Likely due to working backwards on the significand/mantissa first which has to be done the long way due to negative exponents.

      • Durallymax (Customer)

        The j is unnecessary as well, but makes it easier to follow IMO.

        • Screenshot 2024-08-26 113414
      • wlindberg86 (Customer)

        @Durallymax (Customer)​ would you mind uploading the file(s) for the logic? I have a hard time following through explanations and learn so much better being able to physically move through the logic.

  • OkiePC (Customer)

    And don't forget to write a snarky email to the manufacturer that decided to put you through all this heartache rather than transmit the data as a PLC friendly 32 bit float or integer with implied decimal like every other manufacturer with any sense about the needs of the PLC programmer.

10 of 15