I am trying to use a Type-C thermocouple with a MAX31856 thermocouple IC. This means that I must read the thermocouple voltage directly (in mV) and convert the voltage to temperature in software using a lookup table. I cannot understand the formula given on page 20 of the MAX31856 datasheet on how to convert the "code" received from the 31856 to mV. I am writing my program in python. Can anyone explain to me the steps involved in implementing this equation? Maxim tech support simply refers me to the datasheet. Thanks in advance for any advice.


Welcome. Presumably you are referring to this datasheet (please provide a link to the datasheet in the future) and the below:

enter image description here

So you are going to decide which full scale mV to use (+/-19.531 or +/-78.125). The latter will cover the full range of the Type C thermocouple, but will give less resolution and probably more noise. The former will cover you up to only around 1050 to 1100°C depending on the ambient temperature (less if the chip happens to be relatively cold).

So if you treat the number you read from the chip as a 19-bit signed number (presumably 2's complement), you will have a number between 0x1FFFF and 0x60000, representing mV from +78.125mV to -78.125mV using the Gain = 8. So if you convert to floating point and divide that 19-bit signed integer by (8.0 * 1.6 * 2^17) = 1677721.6 you will have the input voltage in volts. You would normally want to sign-extend the 19-bit integer.

After that you'll have to read the cold junction voltage in degrees, convert and possibly delinearize that to mV-equivalent for type C (or do a slapdash linear approximation), sum that with the mV sensor reading and then linearize the resulting voltage to read in degrees. The details of that are complex and well outside of the scope of this answer.

Python's 64-bit floats are more than good enough for the calculation. To do the sign extension, that's really a Python question, for which this answer is probably helpful.

def sign_extending(x, b):
if x&(1<<(b-1)): # is the highest bit (sign) set? (x>>(b-1)) would be faster
    return x-(1<<b) # 2s complement
return x

Where you would use b = 19, so

volts = sign_extending(y,19)/1677721.6

(where y is the code read from the chip)

  • \$\begingroup\$ Wow! Thank you for taking the time to explain that in that detail. I needed the help and haven't understood how to solve that equation with the bit manipulation. We run the furnaces to 2200C so will need the full range. I hope to use this module... pypi.org/project/thermocouples_reference to do the linearization. We'll see how it all comes together. Thanks again very much. \$\endgroup\$ – tinker242 Aug 13 at 2:05
  • 1
    \$\begingroup\$ It's taken me a long time to get back to this issue... but I wanted to get back to you and THANK YOU again for helping me through the math here. The result is 100% perfect and has finally put this problem to rest! Very much of a help to me, and I appreciate it, and thank you. \$\endgroup\$ – tinker242 Sep 8 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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