This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to calculate J-Type Thermocouple Temperature using ADS1118?

Other Parts Discussed in Thread: ADS1118

Hello!! I am using ADS1118 and i have to calculate the J-Type thermocouple temperature with it.

My circuit is as follow:-


I am using ADS1118 in Single Shot mode
Configuration register values are as follow:-
Internal Temperature - 0x859B
First Differential Channel - 0x858B
Second Differential Channel - 0xB58B

Internal Temperature is working properly, but help me to calculate the Thermocouple temperature using above circuit.

  • Xpress.


    First of all, it looks like you have the registers written correctly. All of them are set to ranges of +/-2.048V, 128SPS, with the DRDY pull up enabled. However, I would probably use the smallest range possible (+/-256mV) just so that you have the best resolution possible.

    After that, are you having a problem calculating the voltage? It seems that if you can read the temperature sensor, you should be able to read the voltage as well. Regardless, you should be able to calculate the ADC voltage based on the Data Format section of the datasheet on page 17.

    Beyond that, to convert this voltage to temperature, for a J-type thermocouple you can use the look-up table provided by Omega for the following reference table:

    http://www.omega.com/temperature/z/pdf/z216-217.pdf

    Or if you want to use try to calculate out a temperature, you can use a multi-order polynomial expression as found on page 6 in table 4 of the following application note:

    http://www.omega.com/temperature/z/pdf/z021-032.pdf

    If this doesn't answer your question, post back and you can ask again.


    Joseph Wu
  • Thanks for your instant reply.

    Yes the information is given in datasheet, which is as follow:-

    The procedure to actually achieve cold-junction compensation is simple and can be done in several ways. One
    way is to interleave readings between the thermocouple inputs and the temperature sensor. That is, acquire one
    on-chip temperature result for every thermocouple ADC voltage measured. If the cold junction is in a very stable
    environment, more periodic cold junction measurements may be sufficient. These operations yield two results for
    every thermocouple measurement and cold junction measurement cycle: the thermocouple voltage V TC and the
    on-chip temperature T CJC . In order to account for the cold junction, the temperature sensor within the ADS1118
    must first be converted to a voltage proportional to the thermocouple currently being used yielding V CJC . This
    conversion is generally accomplished by performing a reverse lookup on the table being used for the
    thermocouple voltage to temperature conversion. Then, adding the two voltages yields the thermocouple
    compensated voltage (V Actual ), where V CJC + V TC = V Actual . V Actual is then converted to temperature using the
    same lookup table as before, yielding T Actual .



    The look up table which you have given is too big, how i will store it in micro-controller and then how to use it.
    Apart from this Cold Junction Temperature is also converted to Voltage and then added to thermocouple voltage, how will i convert cold junction temperature to voltage.
    Can you provide me an example how to use this look up table in firmware and do calculations to obtain thermocouple temperature.

  • Xpress,

    If you can't store the table, then definitely read the second application note. Again I'll post the link below:

    http://www.omega.com/temperature/z/pdf/z021-032.pdf

    Using Table 4, you can take the voltage to get the temperature through calculating it by using a polynomial expression. Going back the other direction from temperature to voltage is a little more difficult. In that case, you have to rely on perhaps reducing the polynomial expression, eliminating the higher order terms.

    Note that the voltage term is small which makes higher orders even smaller. Also, since the cold junction is usually restricted to a smaller range temperature range, you can better get away with an approximation. I would note that if the cold junction is between 20C and 40C, the voltage measurement will be in a range of under 600uV (from -335uV to +225uV). In that amount of voltage range, you could probably get away with a linear approximation.


    Joseph Wu
  • Joseph Wu thanks for your reply,

    I am getting same internal temperature data for both differential channels,


    Here is my Code:-

    _TC_Comm_16(TC_TEMP); // discard data, configure TC_TEMP
    thermo.tc_dev1.cj_temp = _TC_Comm_16(TC_TC01); // read TC_TEMP, configure TC_TC01
    Serial.println(thermo.tc_dev1.cj_temp,HEX);
    _TC_Comm_16(TC_TC01); // discard data, configure TC_TC01
    tc_dev1.thermocouple1 = _TC_Comm_16(TC_TC23); // read TC_TC01, configure TC_TC02
    Serial.println(thermo.tc_dev1.thermocouple1,HEX);
    _TC_Comm_16(TC_TC23); // discard data, configure TC_TC23 
    thermo.tc_dev1.thermocouple2 = _TC_Comm_16(TC_TEMP); // read TC_TC02, configure TC_TEMP
    Serial.println(thermo.tc_dev1.thermocouple2,HEX);

    and the function is as follow:-

    static u16_t _TC_Comm_16(u16_t config_word)
    {
    u16_t ret_val;
    u8_t comm_byte; 
    // set SS pin LOW (enable)
    digitalWrite(SS, LOW); 
    // send command
    comm_byte = SPI.transfer(HI16(config_word)); // Data MSB
    ret_val = (u16_t)comm_byte;
    comm_byte = SPI.transfer(LO16(config_word)); // Data LSB
    ret_val = (ret_val << 8) | (u16_t)comm_byte;
    
    // set SS pin HIGH (disable)
    digitalWrite(SS, HIGH);
    return ret_val;
    }
    

    No thermocouple is connected right now, i must get full swing of voltage.



  • _TC_Comm_16(TC_TEMP); // discard data, configure TC_TEMP
    delay(150);
    thermo.tc_dev1.cj_temp = _TC_Comm_16(TC_TC01); // read TC_TEMP, configure TC_TC01
    delay(150);
    Serial.println(thermo.tc_dev1.cj_temp,HEX);
    _TC_Comm_16(TC_TC01); // discard data, configure TC_TC01
    delay(150);
    tc_dev1.thermocouple1 = _TC_Comm_16(TC_TC23); // read TC_TC01, configure TC_TC02
    delay(150);
    Serial.println(thermo.tc_dev1.thermocouple1,HEX);
    _TC_Comm_16(TC_TC23); // discard data, configure TC_TC23 
    delay(150);
    thermo.tc_dev1.thermocouple2 = _TC_Comm_16(TC_TEMP); // read TC_TC02, configure TC_TEMP
    delay(150);
    Serial.println(thermo.tc_dev1.thermocouple2,HEX);

    After adding the delay of 150 millisconds i am getting the following results:-

    CD4 => 25.65 deg Celcius (Internal Temperature)
    7FFF => This is for thermocouple 1 Port (No Thermocouple is connected, that's why i am getting 7FFF full swing i think)
    7FFF => This is for thermocouple 2 Port (No Thermocouple is connected, that's why i am getting 7FFF full swing i think)


    Previously i am getting the same value is due to the fact that the conversion for differential channels are not completed and i am reading the old data of internal temperature. Please correct me if i am wrong some where.

    One strange thing is that, when i connect thermocouple in the thermocouple connector, i am getting 0/1/2/3 Hex values on the channel the thermocouple is connected.
    Right now i don't know which thermocouple is this which i am connecting (as we have ordered J-Type but it will take some time), but i can tell the colors of wires, one is yellow and another is red.
    And at other end it is having a connector like this.




    I am trying to understand the whole application, that's why asking basic questions.



  • As per this link, from NI website

    I found that i am using K-type thermocouple because color is red and yellow.

    But the main problem is that why i am not getting voltage when connecting this thermocouple to thermocouple connector.

  • Now i had set the PGA to 111 = FS is ±0.256 V
    And put the theromocouple in Hot water taken from coffee machine.
    Now i am getting value 0xA5 and that are continuously decreasing wrt time as water is getting cooler wrt time.

    How to convert this value into voltage, this is 16-bit adc and what is the reference voltage, can you please tell me the formula to calculate it.

    Right now, i had set the PGA to ±0.256 V is it sufficient for J-type Thermocouples.

    I am assuming that ±0.256 V PGA means, the highest voltage measured by ADS1118 is 0.256V and lowest is -0.256V.
    Am i right, please correct if wrong.
  • Xpress,


    I'll just answer a few of these as they come up, since you've posted quite a bit since my last answer.

    It looks like you're using the internal temperature sensor fine. The result looks normal. Unplugged, the other two channels can read full scale when nothing is attached, so 7FFF is not an unreasonable result.

    The output hex values are small, but that may be because you're not in a higher gain to get better resolution. I'll address that from responding to one of your next posts.

    The connector you show is for a k-type thermocouple. Omega has a listing of the various connector colors here:

    http://www.omega.com/temperature/pdf/tc_colorcodes.pdf


    Joseph Wu
  • Xpress.

    Setting the PGA bits to 111 will give you the full scale range of ±0.256 V. Again, I'd refer to page 17 of the datasheet. Note that you do not need the reference voltage. The full scale is already given as ±0.256 V and the output data codes go from FFFFh (at -256mV) to 7FFFh (at 256mV) with the twos complement notation.

    If you're reading 00A5h, this converts to 165 decimal. Since the full scale is 256mV, use:

    (256mV*165)/(2^15) = 1.289mV of measured value

    Looking a the k-type table from Omega (http://www.omega.com/temperature/z/pdf/z204-206.pdf), you'll get a equivalent temperature of about 32C.

    Joseph Wu

  • Thanks for your reply.
    If considering above example, then please tell me why 2^15, as ADC is of 16-bit, then why you have taken 2^15 in denominator.
    Please tell me the logic behind this.
    And as per the above formula, i had tested that my temperature readings are almost correct, there is a few degree deviation, but that is acceptable to me right now.
    In the above example i get 1.289mV then i convert the cold junction temperature into voltage and then add both.
    Vact = Vcj + Vtc
    Then i use this Vact to determine the temperature, this all working.

    But what will be the best way to calculate the temperature, i prefer look up table method, but somewhat confused.
    And i can take my cold junction temperature as constant for now for 28deg C which will give 1.122mV value.
  • Xpress,


    It sounds like you've got it working ok.

    For a 16-bit converter, the full 16 bits are used to represent the entire range. In this case it goes to +/- 0.256V. I just simplified the math so that it's 15 bits from 0 to 0.256V (the equivalent of half the range.

    As for the temperature calculation, I think the equation given by Omega would be the easiest to implement.


    Joseph Wu
  • Thanks,
    My problem is almost solved, just have to decide which method to use.
    As i am using 8-bit micro-controller, so the formula given in Table 4, is quite complicated and can produce inaccurate results due to floating point constants.
    Well i will try it, apart from it can be you please tell me about look up table method.

    What i was thinking of look up table method is that, for every ADC count i will write the temperature value, but in that way, it will create a very big table.
    If i will write temperature for each adc count, then for example for 999 deg C voltage will be 41mV and for 41mV -> maximum adc count will be 5248.
    But i think, it can be simplified further, for each degree Celsius is considered.
    Can you please help in this method.

    I will try both method and will implement that which is more accurate.
    Thanks for your help.
  • Xpress,


    I don't think I have much to add about the look up table. It's just the values given in the pdf that came from Omega.

    If there are problems with numerical accuracy, then perhaps you could simplify it and construct a piecewise linear equation to get the temperature.


    Joseph Wu