- Published: Wednesday, 19 January 2011
- Written by Jon Chandler
- Hits: 11366
The photo below shows the TAP-28, TMP513 and PICkit 2 on a mounting board I made. With small, lightweight boards, it's easy for everything to go flying when pulled off the bench by a cable. Since testing of the thermocouple required many trips to the kitchen to do a boiling water calibration, having evening secured in one place made a handy solution.
Thermocouples are popular temperature measurement sensors that cover a temperature range from well below zero °C to over a thousand °C. They have good accuracy, are available in many configurations and are inexpensive. This is not to say that they are easy to use! Thermocouple are a measurement challenge:
- Output levels are less than 50 mV and may be positive or negative
- The “cold junction” temperature must be compensated
- The output response is non-linear
Historically, measurement solutions to meet these challenges have been complex requiring several ICs and many discrete components. A few dedicated single chip solutions exist but all have shortcomings, including cost and availability.
I2C Single-Chip Solution
The TI TMP512/TMP513 Temperature and Power Supply System Monitor provides an ideal single-chip solution for thermocouple measurement. The chip features a 12-bit ADC with an input range of 40 mV that can handle bi-polar signals, and an accurate on-chip temperature sensor for reference junction compensation. Where maximum measurement accuracy is required, external PN temperature sensors may be used to measure temperature at the junction point.
The thermocouple measurement circuit is shown below. Either the TMP512 or TMP513 may be used in the circuit.
The thermocouple is connected between VIN+ and VIN-. The connection between the thermocouple wires and PCB traces or the connection of the thermocouple connector and PCB traces form the reference junction. This should be as close to the TMP51x as possible and away from any heat sources so that the temperature measured by the chip’s sensor is a true representation of the reference junction temperature.
If this connection must be made some distance from the chip or the maximum possible accuracy is desired, an external transistor may be used. Some thermocouple connectors even have a clip so that a TO-92-package can be placed right on the terminals.
The simplest circuit implementation is shown below. Input filtering may be added at the thermocouple input – consult the TMP512/TMP513 data sheet for information on this and on remote temperature sensors.
Only a few features of the TMP512/TMP513 are used by this application so only a few of the registers are accessed. Most options are left in the default state.
Step 1 – Reset the TMP512/TMP513
Do this on program initialization to ensure known state.
Step 2 – Initialize the TMP512/TMP513
Set the TMP512/TMP513 for thermocouple readings. The default settings for the integral temperature sensor are satisfactory.
D14: Continuous Measurements
D12, D11: PGA = 1 for T/C Measurement (40 mV range)
D6 – D3: 12-bit Measurement for T/C, 16 averages
D2 – D0: Mode – Shunt Voltage (T/C) only, continuous
Step 3 – Read the Thermocouple Voltage
The thermocouple voltage will be negative if the thermocouple temperature is below the reference junction temperature. A negative value is indicated when the sign bits = 1.
The value contained in D11:D0 x 10 is the thermocouple voltage in µV if it is positive.
If the value is negative, the two’s complement must be calculated – see the following section.
Calculating the Two’s Complement
When the sign bits are negative, the thermocouple temperature is negative with respect to the reference junction. The two’s complement must be calculated to determine the negative voltage.
Invert each bit. The easiest way is to use the NOT function:
TCValue = NOT(TCValue)
Add 1 to the value:
TCValue = TCValue + 1
Multiply the result times -10 to obtain the thermocouple voltage in µV; remember to use a variable type that can handle a negative number.
Step 4 – Read the Reference Junction Temperature
D15:D3 contain the local (reference junction) temperature. Read register 4, shift the data right 3 bits (or divide by 8) and multiply the result by 0.0625 to obtain the temperature in °C.
Calculating the Thermocouple Temperature
The output voltage of the thermocouple is non-linear. The easiest way to calculate the temperature on a microcontroller is using a lookup table. Tables are available on-line for all types of thermocouples. An effective way to achieve good accuracy is to use a table that lists voltages in one degree increments (use a Celsius table for the readings shown here) and interpolate between the values for higher resolution. This keeps the table size reasonable while keeping the accuracy high.
To calculate the actual thermocouple temperature:
- Determine the temperature for the measured thermocouple voltage.
- Add the reference junction temperature to this value to obtain the actual temperature at the thermocouple junction.
Sample code and Swordfish modules are below.
Cold-Junction-Compensated K-Thermocouple-to-Digital Converter (0°C to +1024°C)
MAX6674 - Cold-Junction-Compensated K-Thermocouple-to-Digital Converter (0°C to +128°C)
These Dallas-Maxim use an SPI interface. They are limited to Type-K thermocouples, expensive
Type K Thermocouple Amplifier with Cold Junction Compensation
Type J Thermocouple Amplifier with Cold Junction Compensation
These Analog Devices parts have an analog output of 10 mV/°C. The measurement range is
The TMP512/TMP513 circuit is extremely simple. The prototype was built on an SOIC-28 adapter board, which allowed space to add a six-pin connector for use with the TAP-28 PIC application board.
The photo shows a TMP513 mounted to the board along with a 0.1 µF bypass capacitor. The two-pin gold-plated header is for the thermocouple. Point-to-point wiring on the bottom of the board completes the connections.
The six pin header has the I2C SDA and SCL lines along with power and ground. The pullup resistors for the SCL and SDA lines are on the TAP-28 board.
Initial testing was made using a Type K thermocouple, which provides a measurement range of -269°C to 759°C. The upper end of the range was limited to table values that fit in an integer format (±32767).
The TAP-28 board used a PIC18F242 with a 20 MHz crystal and hardware I2C although most any type of microcontroller should work fine. The picture below shows the TAP-28 and thermocouple circuit board, connected with a six-conductor cable.
Two modules are provided to use the TMP513 thermocouple circuit with Swordfish. The first module is the thermocouple table. This is a listing of voltage levels produced by the thermocouple junction at 1°C increments. The table provided is for Type K thermocouples, and is adapted from the charts that can be found on-line. The measurement range is -270ºC to 760ºC. The range of a Type K thermocouple is up to 1300ºC but the table is limited to the range of values that fit in an integer variable.
Tables for other types of thermocouples may be made. The values in the table are in μV. Most on-line tables are mV. The values are multiplied by 1000 to make them integer values. Three values aside from the thermocouple potentials are included in the table:
|TableOffset||Temperature corresponding to the first table value|
|TableType||Type of thermocouple to which the table applies|
|TableValues||Total number of enteries in the table|
The TMP513 uses an I2C interface. This module handles the I2C protocol to set and read the required registers on the TMP513, and converts the register values to cold junction temperature and thermocouple temperature. The module supports three commands:
ReadColdJuncttemp: Returns the temperature of the TMP513 internal temperature sensor in degrees C x 10. This value is used in compensating the thermocouple but it's built into the next command.
ReadTC: Returns the temperature of the thermocouple. The voltage of the thermocouple junction is read, compared against the thermocouple table. The temperature is interpolated for the nearest table values for good accuracy. The cold junction temperature is read and added to the thermocouple value to provide the actual temperature of the thermocouple sensor,
Configures the TMP513 chip
Returns the integer value of the cold junction temperature in degrees C x 10
Returns the integer value of the thermocouple junction temperature in degrees C x 10. The result is compensated for the cold junction temperature.
|I2Cdevice||The address of the TMP513 (only change if default is not correct)|
|TableType||The type of thermocouple table being used|
The Swordfish module makes reading a thermocouple extremely easy. The code shown below reads the thermocouple and write the code to the PICkit UART tool using software UART code.
The thermocouple I'm using is a tiny bead type on the end of a wire, which cost a buck or two on ebay. The temperature reading is very responsive since the bead is so small. The temperatures compare favorably with those from a digital oven thermometer taking over a room temperature - 50°C range, and the results taken in an ice bath and boiling water are spot on.
For further information, check out the forum thread posted during the development of the TMP513 circuit. There are a number of background links along with application information.