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:
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)