Can anyone please help me understand how I can convert data from a sensor register to a float value? Say I am reading the sensor register as following:

R = readRegister(RRegister);

Where readRegister returns uint16_t type data. Now my question is how should I convert this R to get a value for example 150.134.


Edit 1: The register I am trying to read is 14h on page 34. Link of the user guide: [https://pdfserv.maximintegrated.com/en/an/user-guide-6597-max1726x-m5-ez-rev3-p4.pdf][1]

  • 2
    \$\begingroup\$ Can you provide a part number for the sensor? It would help a great deal. \$\endgroup\$ Jul 14, 2020 at 18:05
  • \$\begingroup\$ That totaly depends on the way the sensor is sending the information... Link a datasheet to the sensor, otherwise we won't be able to help you. \$\endgroup\$
    – jusaca
    Jul 14, 2020 at 18:06
  • \$\begingroup\$ Does this answer your question? Conversion of 12 bit ADC/DAC data to floating point for PID operation \$\endgroup\$
    – DKNguyen
    Jul 14, 2020 at 18:49

2 Answers 2


As other commenters point out, if you provide the data sheet and the processor info, and preferably with a wiring diagram, we can help you further.

You need to read the sensor data sheet and determine how it maps a measured value (speed, position, weight, temperature) to a uint16.

If the sensor is analog and you are using an analog input into your processor, then you also have to determine how the internal ADC maps the analog input to a digital value. If the sensor has a digital output, then the data sheet probably says it all.

Look for how it represents 0, the max, and what the step size is.

The full uint16 range may not be used, and the data may be left or right justified (padded with zeros on the right or left).

Once you have all this, you need to write-up a formula to calculate the "real" value from the uint16. It could be something

 Sensor_Reading = R * a + b


 Sensor_Reading = (R-b) * a

Usually the mapping is linear, and if you are lucky, then b=0.

If you are very unlucky, the mapping is not linear, and you have to use a LUT (look-up-table) or a more complicated formula to map a register value to a real value.

  • \$\begingroup\$ In other words, just throw the register into a float calculation that divides it by the full scale real-world value that the register's full scale reading is supposed to represent to turn it into a float of the units you need. If bipolar, you may need to offset it prior to division so it centers around zero. \$\endgroup\$
    – DKNguyen
    Jul 14, 2020 at 18:41
  • \$\begingroup\$ Indeed @DKNguyen, but given the type of question, I wasn't sure whether a short answer like yours would suffice or confuse the OP. Let's see how far they get. \$\endgroup\$
    – P2000
    Jul 14, 2020 at 18:44

That document does not describe how to do it. The chip datasheet does.

It defines that resistance measurements are made with LSB resolution of 1/4096 of an ohm, unless told otherwise.

So as the datasheet example says, a register value of 0x290 means the reaistance is 656/4096 = 0.1602 ohms.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.