Interfacing a K-type thermocouple using only microcontroller ADC features? - Page 1
Forum section: electronics / projects

author: HwAoRrDk
author_rank: Super Contributor
timestamp: February 27, 2019, 04:58:34 pm
content: I have been contemplating an idea I had regarding whether it is feasible to interface with a K-type thermocouple using nothing but the features available in a moderately-equipped microcontroller - namely, an ADC with differential inputs, a programmable gain amplifier, and an internal temperature sensor. I'm wondering whether it's something worth trying, and whether the measurements achievable using such a design would be useful.The ADC on the microcontroller in question claims the following features:- 10-bit resolution- Differential input channels- Programmable gain amplification of differential inputs, of x5, x10, x20 and x40.- Internal temperature sensor- Internal 2.56V reference.So, I was thinking of an arrangement thus:The thermocouple's terminals are connected directly to a pair of differential ADC inputs on the micro. It will be configured to apply a x40 gain amplification on the signal, and reference that against the internal 2.56V reference. I think this should give a large enough signal for a K-type. Then, to apply cold junction compensation, the internal temperature sensor is read as the cold junction temperature, and the compensation is done in software. I guess that's probably 'good enough' so long as the junction and MCU are close together on the same PCB, in the same enclosure.However, I think there are a number of possible sticking points, some of which I'm unsure of the weight of, if they are even concerns at all.To start with, the datasheet says that "On the amplified channels, 8-bit resolution can be expected". I don't understand why they say 8-bit, as while I get that because the input is differential, one bit must be used to represent the sign, that still leaves 9 bits. And they state the range of output values will be between 0x200 and 0x1FF. A typo perhaps? Or are they suggesting something about the effective accuracy?The amplifier circuitry is described as a 'switching capacitor' amplifier. What does this mean? The datasheet is fairly brief about the details, only really explaining that it works off a synchronisation clock, and that a stable input value must be present during a certain number of clock cycles in order to ensure an accurate result. Does this work on a similar principle to a Cockcroft-Walton circuit? It sounds to me like such a thing would not be useful for very high bandwidth signals, but I doubt that would be a problem in this use-case.Also, the amplifier gain claims 5% accuracy. I presume this means that the actual gain figure is not exact, and could be plus-or-minus that amount. So for example, a x40 gain could be anywhere between x38 and x42? Would this be a consistent inaccuracy, or variable, affected by operating conditions, etc?I understand MCU internal temperature sensors are, out of the box, generally not very accurate at all (typically +/- 10C), so I am assuming calibration will be needed here, for at least the ambient range that the device will be expected to be used in.I don't know what the accuracy of the internal voltage reference is, and how it varies. Couldn't find that information in the datasheet, if it exists there at all.Given all the above, I'm wondering what kind of accuracy and precision I can expect from such a solution (assuming it's not a non-starter overall). My attempt at some quick back-of-the-envelope maths shows that, given a K-type thermocouple measuring between 0 and 1000C (so a max input voltage approx. 40 mV), I will get a resolution of about 3C. That sounds fairly reasonable for what I was thinking of doing. I would probably be okay with even 5C resolution! But I'm not sure about how to go about working out what kind of accuracy is to be expected.Is it worth trying to implement this? Are there any show-stoppers I haven't thought about?Yes, I have considered taking the easy route and using something like a MAX31855, but those are quite expensive and I thought it would be a good exercise to try and 'make do with what you've got'.

author: jmelson
author_rank: Super Contributor
timestamp: February 27, 2019, 08:18:44 pm
content: 100 C difference on a K thermocouple give you 4 mV of potential. That's NOT a lot to work with. Unless you are checking ceramic kilns or steel furnaces, your X40 amp is not enough. Even at full range (1370 C) you only get 55 mV out. 10 bits out of a 2.56 V reference gives 2.5 mV resolution on the ADC. dividing by the gain give a resolution at the input of 62.5 uV. A degree C is about 40 uV. So, you'd have a resolution of 1.56 C (but it gets messier when you add in the polynomial correction.)Jon

author: HwAoRrDk
author_rank: Super Contributor
timestamp: February 27, 2019, 08:52:00 pm
content: Quote from: jmelson on February 27, 2019, 08:18:44 pmYou missed where I said that the ADC output is a signed 9 bit value when using the differential inputs. So it'll be 4 mV ADC resolution, giving 125 uV at the input, for 3.125 C. So, yeah, my maths was about right. But, like I said, I'd be satisfied with 5 C resolution, if Icanget 3, it'll be good.I'm still puzzled why the datasheet says it is 8 bit in differential mode. I found it even says that in the ADC characteristics table. But all the examples show 9 bit values.Quote from: jmelson on February 27, 2019, 08:18:44 pmAh, I knew there was something I'd forgotten. I need to go watch Dave's video on thermocouples again.Yes, the response curve is not linear, is it? That is, it's not exactly 40 uV/C all the way across the temperature range, is it? I seem to recall there are pre-defined lookup tables for doing that correction. Published by NIST? Or ANSI? Or was is it the ISO?

author: Siwastaja
author_rank: Super Contributor
timestamp: February 27, 2019, 08:57:36 pm
content: Quote from: HwAoRrDk on February 27, 2019, 08:52:00 pmWould be easier to answer if you revealed your mystery MCU to us.It may be "software developer speak", from a digital guy, for digital guys. It may just mean ENOB.

author: aheid
author_rank: Regular Contributor
timestamp: February 27, 2019, 09:08:33 pm
content: Several STM32s (like STMF3 series) have differential 12bit ADCs, and coefficients for temp compensation of internal 1.2V reference. Would at least give a bit more margin, no? Not that I have any experience to say if it is still futile...

author: snarkysparky
author_rank: Frequent Contributor
timestamp: February 27, 2019, 09:13:35 pm
content: precision op amp with high gain is needed first or you won't get much good result.I made mine with a 110 gain then into ADC on a pic with a 12 bit ADC. Programmed in the type K polynomials to correct the non linearcharacteristic. for a range of ambient to 400 F. ( smoker project ).

author: HwAoRrDk
author_rank: Super Contributor
timestamp: February 27, 2019, 09:21:42 pm
content: Quote from: Siwastaja on February 27, 2019, 08:57:36 pmSorry, it's the ATmega[16/32/64]M1 series. The ATmega[16/32]U4 and ATmega[164/324/etc] also have a differential features that I believe works in the same way.

author: splin
author_rank: Frequent Contributor
timestamp: March 05, 2019, 10:30:11 pm
content: Quote from: HwAoRrDk on February 27, 2019, 08:52:00 pmIt's because the programmable gain stage used in differential mode is implemented with switched capacitor amplifiers and they're rather noisy so the effective resolution is 8 bits. Oddly the datasheet shows 8 bits resolution for all gains of 5x to 40x - I would have expected the resolution to drop more at higher gains as the input noise is also multiplied by the gain. 8 bits is pretty terrible and remember that is RMS noise, so noise free resolution might only be 6 to 6 1/2 bits! Note that the DS doesn't say if that is 8 bits + sign or 8 bits including sign.Filtering the ADC output by averaging, reduces random noise increasing the resolution - but not noise that is correlated with the input signal so I'm not sure how effective it will be with the switched capactor amplifier noise. Still, I wouldn't be surprised if you could get to 12 bits by averaging a few hundred thousand samples or more. So 2.56V/2^12/40 = 15.6uV = 0.4C.But then you hit the next problem - the ADC linearity error is up to 3.5 LSBs in differential mode i.e. 2^3.5/2^12 * 2.56V / 40 = 177uV or +/- 4.4C. You could calibrate it, but that is a pain and non linearity changes with temperature. You might be helped by the relatively low gain - the biggest linearity errors in an SAR ADC usually occur at input levels where the most significant bits of the output code change value because of mismatches in the resistor or capacitor weightings. So if your total input signal range is 300C, voltage range = 40uV * 300 * 40 = .48V. This is less than a quarter of the reference voltage, so if you could offset the input signal a little to ensure that the top two MSBs can't change over your full input signal range, which might limit the worse case error considerably.You would need to experiment. Also don't forget that in differential mode the ADC timing is more complicated as described in section 18.10 of the DS.

author: ogden
author_rank: Super Contributor
timestamp: March 05, 2019, 10:43:00 pm
content: Quote from: HwAoRrDk on February 27, 2019, 09:21:42 pmMsp430 with SD ADC is better suited for this application. TI even have appnotes of "K-type thermocouple using only microcontroller":http://www.ti.com/lit/an/slaa218/slaa218.pdfhttp://www.ti.com/lit/an/slaa216a/slaa216a.pdf

author: tecman
author_rank: Frequent Contributor
timestamp: March 08, 2019, 08:36:57 pm
content: Another solution is to use:https://www.maximintegrated.com/en/products/sensors/MAX6675.htmlAround $ 4 and simple SPI interfacepaul

author: ogden
author_rank: Super Contributor
timestamp: March 08, 2019, 08:54:07 pm
content: Quote from: tecman on March 08, 2019, 08:36:57 pmBefore posting, you are advised to readSubjectof the thread which states "using only microcontroller ADC features"

author: RoGeorge
author_rank: Super Contributor
timestamp: March 08, 2019, 08:55:07 pm
content: Using only an MCU is possible but cumbersome, better use a dedicated IC for better performance.Ex: ADS1118http://www.ti.com/lit/ds/sbas457e/sbas457e.pdf