Monday, June 14, 2010

Thermometer using a thermocouple, instrumentation amplifer, and microcontroller

Cobbled up an instrumentation amplifier with a gain of 200 using three op amps (3/4 of an MCP609), six 5% 20K carbon resistors manually matched to less than 1% tolerance using a DMM and a gain resistor of 200ohms. Added a voltage divider buffered with two op amps (MCP6232) for two level shift voltages at the input of the IA and its voltage reference pin. Then plugged in a 30yr old Omron E52 CA1D type K thermocouple and had its obscenely noisy outputs decoupled with 1nF and 100nF ceramic caps. Filtered the gained signal with a 1st order active low pass filter (100Kohm 5% carbon, 1uF tantalum, 1/4 of the MCP609) with a cut off frequency of 1.6Hz. Sent the signal and reference-pin level shift voltage to the onboard ADC of a PIC16F690, employed a 4.096-Volt, 1%-tolerance voltage reference (MCP1541) and a 2-degree-tolerance silicon temperture sensor (MCP9700) to measure cold junction temperature. Juggled all the resulting 10-bit numbers around using floating piont and integer math and finally dumped the values to an Displaytech 162F LCD screen--so that pathetic 10Hz, decimal-based creatures like me can see the results. Well, after much tweaking and error correction of the microcontroller firmware, the breadboarded circuit actually measured steaming bubbling boiling water (at sea level) to be 99 to 100 Celsius. Not bad I say. Indeed the 1-degree accuracy amazes me given how much error and noise could've thrown the accuracy off by several degrees. Given the (sub)millivolt signal and the many hardware components involved in the signal conditioning and its conversion from analog to digital, there are numerous sources of errors which can significantly affect the accuracy of the measurement. Here are some error sources which come to mind. Some are probably not that significant at the 1 degree accuracy I've specified as my target:
  • thermocouple cold junction temperature and temperature of IC that measures the cold junction temperature 
  • IC temperature sensor tolerance  
  • op amp offset voltage
  • offset voltage drift
  • mismatched resistors in the instrumentation amplifier
  • resistor value drift
  • resistor noise
  • gain resistor value and stability
  • op amp noise
  • common mode rejection 
  • ADC reference voltage tolerance/drift
  • ADC quantization errors
  •  noise from digital circuits affecting analog circuit
  •  EMI, RF, and 50/60Hz power line hum and its harmonics

Circuit Details

A type K thermocouple (TC) is used to sense temperature. Its + and - output are both level shifted to Vref/2, where Vref = 4.096V. An instrumentation amplifier made from three of the quad op amp MCP609 amplifies the TC voltage by 200 and removes the level shift voltage. Reference pin of the IA is connected to +0.4V in order that TC may be able to sense temperatures less than the cold junction (CJ) temperature. The Microchip PIC 16F690's 10-bit ADC digitizes gained TC voltage and the level shift voltage applied to IA ref pin. The latter is then subtracted from the former, thus leaving only the amplified TC voltage. This value now corresponds to a temperature relative to the CJ temperature. A lookup table (values are stored in a 24-element, 1-dimensional array) is used to determine the temperature of TC to within 20 degrees Celsius. Interpolation is then used to determine temperature to within 1 degree. CJ temperature is sensed by a Microchip MCP9700 temperature sensor. The ADC digitizes its output and firmware converts it to degrees Celsius. Actual thermocouple temperature is obtained by adding CJ and TC. Temperature range that can be measured is approximately between -40 to 420 Celsius. I really don't have much need for a thermometer measuring anything colder than a freezer, so the level shifting voltage at the IA reference pin need not be greater than 0.5V. On the other hand I do want the circuit to be able to measure high temperatures, >400 Celsius--thus the need to keep the level shifting voltage as low as possible. Decreasing the gain is an option but I can't get myself to part with the nice round figure of 200.

AIA1, AIA2, and AIA3 are configured as a classic three-op amp instrumentation amplifier. R1 = R2 = R3 = R4 = R5 = R6 = 20K. Gain is set by RG and is given by the equation (2R1/RG + 1). ALPF (1/4 of the MCP609) is used as an active low pass filter. Given the 100K 5% carbon resistor and 1uF tantalum capacitor cutoff frequency is 1.6 Hz with a 20dB rolloff. Op amp has a gain of 1. R1 to R6 are 5% carbon resistors which have been measured using a DMM to be within 1% of each other. Gain resistor is a 5% carbon measured at 201 ohms.

VREF (MCP1541) output is 4.096V and is used by ADC as voltage reference. It is also used for the level shift voltages since maximum gained TC output cannot exceed voltage reference voltage. Level shifting voltage VLS1 for TC must be equal to Vref/2, because output of AIA1 = E1 + (E1-E2)*R1/RG and output of AIA2 = E2 - (E1-E2)*R1/RG. The plus and minus (E1-E2)*R1/RG output is symmetrical for both op amps. VLS2 is injected into Vin+ of the difference amplifier to level shift the gained and common-mode-subtracted TC voltage. This is necessary in order to measure temperature when TC is colder than cold junction temperature. Without this level shift any TC temperature below CJ would be result in zero reading because of the single supply. VLS2 is sampled by ADC whenever reading the thermocouple temperature so that it can be deducted from it. Cold junction temperature is read by TS (MCP9700) and added to the computed thermocouple temperature. Ideally TS is placed in contact with the isothermal block to measure cold junction temperature of thermocouple leads.

Cf1a, Cf1b, Cf2a, and Cf2b are ceramic capacitors and are absolutely essential. Without them noise gets injected and IA outputs garbage. 0.1uF capacitor filters out 60Hz noise of metal casings of 60VAC appliances to which thermocouple can come into contact with. 1nF filters out high frequency noise that gets conducted by thermocouple wire acting as an antenna. Capacitors should be placed close to the IA input pins.

Separate VDD and ground connections should be made for analog and digital circuits to reduce digital noise from being injected into analog circuit. A "star" connection should be employed. All op amps are decoupled with 0.1uF caps. (See Analog Devices AD623 Instrumentation Amplifier datasheet Rev.C p.13.)

Some Equations

1. Determining cold junction temperature as measured by a Microchip MCP9700 temperature sensor

MCP9700 output at zero Celsius = 500mV

Let
t = temperature in Celsius (negative when below zero)
V = MCP9700 output voltage = 500mV + 10mV per degree Celsius
CJ = 10-bit ADC reading of MCP9700 output, with the ADC using a 4.096 voltage reference

V = 0.5 + 0.01t
CJ = (0.5 + 0.01t)*1024/4.096
CJ = (0.5 + 0.01t)*250

Therefore
t = CJ/2.5 - 50


2. Determining thermocouple temperature by use of a lookup table and interpolation

Let
TCm = thermocouple voltage at temperature m, where m = -60, -40, -20, 0, 20, ..., 400 Celsius
TCn = thermocouple voltage at temperature n, where n = m + 20
TCr = thermocouple voltage at temperature r -- the temperature of the thermocouple junction relative to the cold junction
s = number of degrees Celsius = r - m

Given that temperature r lies between m and m+20
TCr = TCm + s(TCn - TCm)/20

Given TCr and a table of values for thermocouple at various temperatures we need to look for s in order to determine r. Solving for s:
s = (TCr - TCm)*20/(TCn - TCm)

Temperature at which thermcouple junction is relative to the cold junction is therefore:
r = m + s

Actual temperature of the thermocouple joint is r + t, where t = cold junction temperature

Actual thermocouple output is gained by instrumentation amplifier and then digitized by 10-bit ADC referenced to 4.096 volts. Therefore thermocouple reading that is output by the ADC is = TCr*G*1024/4.096 = TCr*G/4, where G = gain of the IA. Because of this the table of thermocouple values for TCm and TCn are multiplied by G/4 before being used in the above equations.

2 comments:

  1. Your post is very useful and informative. I like your idea of sharing this post. Thank you so much for sharing such an informative post with us. Keep sharing.

    Tubular Heater

    ReplyDelete
  2. You can play a role casino game. like a pure scr payment method, all players will be randomly drawn casino in order to area them at a prescribed time and be smarter than the opponent in a gambling game clip off by the brain. when the exploit to belligerence and receive additional casino games where you can determine your own destiny, rules and payout rates. https://918kiss2020.com/tag/scr/

    ReplyDelete