Analogue tricks to get 16 bits from an 8 bit ADC - Page 1
Forum section: electronics / general

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 10:30:54 am
content: I have had this little idea. If I take a measurement with my ADC on my AVR and I take it as 10 bits for maximum precision (or whatever other word the pedantic might come up with) and then discard the last 2 bits the least significant ones. That gives me a fairly good 8 bit value. If I then subtract 255/256 of my input voltage leaving only one 256th and multiply it 256 times and take another reading in the same manner I can then put these two 8 bit values together into one 16 bit value with appropriate bit shifting of course. The 2nd step is of course a bit extreme so maybe I could work with less bits and slightly higher voltage levels before I end up just reading operational amplifier offset voltages. But I'm sure you get the general theory. Is this something people have done? I need to buffer my input anyway all I would need to do is put it through a differential amplifier with some gain (yes 256 might be a bit excessive) and feed it into a different analogue to digital input. Not much in it really.

author: rob77
author_rank: Super Contributor
timestamp: September 03, 2016, 10:38:11 am
content: anything is possible ! the question is the complexity and cost16bit ADCs cost next to nothing compared to the complexity of the setup which would be needed by your approach (sample MSB 8 bits + amplify & shift signal and sample LSB 8 bits).

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 10:40:51 am
content: True, although all I am using is 1 op amp more I have to buffer the signal anyway and that can be a dual opamp. the uC is not doing a lot so it's not like code overhead is a problem.

author: rob77
author_rank: Super Contributor
timestamp: September 03, 2016, 10:49:22 am
content: Quote from: Simon on September 03, 2016, 10:40:51 amthe shift & amplify would be the tricky part, it would require a very precise shift and amplification to keep the ADC linear and avoid missing codes (you might introduce quite a gap or overlap with incorrect voltage shift). the error in voltage shifting would need to be less than 80uV to avoid a gap/overlap in codes.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 10:51:37 am
content: Which is why I'm thinking that if I use less than the full resolution after the the conversion hopefully most of the error will be lost in dumping 2 or more LSB but yes I see what you mean.

author: wraper
author_rank: Unknown
timestamp: September 03, 2016, 11:04:11 am
content: Won't happen. Half bit uncertainty/change in the first measurement (and it will happen, even if you cut off 2 least significant bits), will make your second measurement completely meaningless. Also it's not like you can do in reasonable way the analog part of it either.

author: voltsandjolts
author_rank: Unknown
timestamp: September 03, 2016, 11:48:00 am
content: Are you describing a zoom ADC architecture?https://www.semtech.com/images/promo/ZoomingADC%20White%20Paper_STD.pdf

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 11:53:43 am
content: Sort of. I am surprised that they make such a thing of rescaling the range of the actual signal as this is an obvious step to increasing resolution. I am now looking at ADC's, with a seperate reference pin i can fine tune the range and get better resolution.My problem is that I am looking at a NTC sensor and from experience i know that they are awful over 20C as the slope is so slight.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 11:56:58 am
content: I am now looking at this chip:http://www.farnell.com/datasheets/1814529.pdf?_ga=1.9153074.646536181.1456469885just a shame it does not have a low voltage ref but that is the least of my problems. The SPI protocol is so easy I'm sure i could hard code it if neccessary.

author: 2N3055
author_rank: Super Contributor
timestamp: September 03, 2016, 12:14:45 pm
content: So you want to measure temperature in a range of about room temperature..What precision do you want... If you want high precision (and repeatability) you might need to go PT sensors...If you don't need much of resolution, use a solid state digitised sensor ...NTC are used because their sensitivity.. they are great for thermostats and likes..With precision NTCs you can measure very precisely, but that is expensive stuff..I just ordered one ADT7410 to try it out.. looks promising if you don+t need lab grade measurement..

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 12:16:17 pm
content: I need to cool and environment with a fan. I have 5 target temperature 5C apart so I'd like to not over or undershoot by more than 2.5C eiher way.

author: wraper
author_rank: Unknown
timestamp: September 03, 2016, 12:23:50 pm
content: Quote from: voltsandjolts on September 03, 2016, 11:48:00 amThat's not really getting 16 bit out of two 8 bit measurements. It's name says what it means. You zoom in into the particular area of interest, not miraculously increasing the resolution. In that paper they just show how they use full range of 10 bit ADC. IMO Simon, you should better explain what is the problem in the first place, not the solution of it you try to implement. As the solution may be wrong. What is the range of the temperature, and required accuracy and precision?

author: wraper
author_rank: Unknown
timestamp: September 03, 2016, 12:37:43 pm
content: Quote from: Simon on September 03, 2016, 12:16:17 pmEven if the range would be 100oC, not <30oC (5x5), I don't see why this needs more than 8 bits.

author: Kalvin
author_rank: Super Contributor
timestamp: September 03, 2016, 12:43:54 pm
content: I guess you could use oversampling to achieve higher resolution:http://www.atmel.com/images/doc8003.pdfFor each additional bit you need four samples ie. 4**N samples for additional N bits. For example, In order to gain six extra bits you need 4**6 = 4096 samples. That is in theory, of course. You need to do some testing with your Arduino, but it shouldn't be too difficult as you have already the ADC up and running anyway.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 12:45:08 pm
content: Yes I could oversample. Yes I have basic code for the ADC on an ATtiny24A

author: wraper
author_rank: Unknown
timestamp: September 03, 2016, 12:46:28 pm
content: If you need to zoom in into particular area of NTC curve, it could be as simple as a few switchable resistors to regulate the current through it.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 12:48:21 pm
content: Well I have found that using a higher voltage and possibly a larger series resistor helps extend the range and increase linearity of the voltage. I'm just trying to get thick libre office calc to do me a table of values and start playing with values if I could get the damn thing to work.

author: Kalvin
author_rank: Super Contributor
timestamp: September 03, 2016, 12:56:23 pm
content: If you are only using the NTC as a temperature sensor, you could possibly use a simple 1N4148 diode as a temperature sensor since it will have approximately 2mV/C tempco. Need more sensitivity? Add two or more diodes in series.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 12:57:31 pm
content: The sensor needs to be on the end of a cable made with suitable material do I'd rather buy an off thre shelf assembly. This is not a one off.

author: Kalvin
author_rank: Super Contributor
timestamp: September 03, 2016, 01:03:40 pm
content: You could also linearize the NTC if that would help you:http://www.edn.com/design/sensors/4429105/Linearize-thermistors-with-new-formulahttps://en.tdk.eu/download/531110/a3be527165c9dd17abca4970f507014f/pdf-applicationnotes.pdfhttp://www.lpi.usra.edu/lunar/ALSEP/pdf/LinearThermistorsUseAsTempSensors%20-%20ATM-1108.pdf

author: madires
author_rank: Super Contributor
timestamp: September 03, 2016, 01:05:45 pm
content: The AVR got an internal bandgap reference, which improves the resolution, when the voltage to measure is lower than the reference's voltage. It's not accurate but stable. So you need to measure the bandgap reference first, assuming you got an accurate 5V Vcc (all done in the firmware). Then select a NTC considering the required voltage divider and temperature window.

author: nctnico
author_rank: Super Contributor
timestamp: September 03, 2016, 01:14:30 pm
content: Quote from: Simon on September 03, 2016, 12:16:17 pmDon't use an NTC but a PT1000 then. Also go for a decent 12bit ADC (which is enough to get about 0.25deg C per bit without needing oversampling) from AD or TI (and not Microchip!).

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 02:34:15 pm
content: I've finally got a spreadsheet to work and found that I will have 15-25 counts per degree C with the AVR 10bit ADC so I think an external one will be unneccesary. I'm using a 10V supply with a 18K pull up on a 10K@25C NTC, I should probably look at my options with the 1.1V ref using 5V so as to save me some circuitry.

author: Howardlong
author_rank: Super Contributor
timestamp: September 03, 2016, 03:07:52 pm
content: Any reasons not to use a pre-calibrated I2C or 1-wire temp sensor?

author: rstofer
author_rank: Super Contributor
timestamp: September 03, 2016, 03:24:51 pm
content: If this is way off, just forget about it...You can change the range and scale of your sensor with an op amp and 4 resistors. As a side benefit, you have low output impedance to drive whatever ADC you want.Check out Section 4.3 of Op Amps For Everyonehttp://www.cypress.com/file/65366/downloadIt's a simple y=mx+b exercise and can be done with a single supply op amp if you choose.That said, it is unlikely that the component parts lead to a perfect solution so don't be surprised if you have to code up a calibration table but the good news is that you can use the entire span of the ADC over a small portion of the sensor output.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 03:39:13 pm
content: Quote from: Howardlong on September 03, 2016, 03:07:52 pmIt has to come on the end of a peice of wire that is flame retardant and be plastic coated to protect from a marine environment

author: wraper
author_rank: Unknown
timestamp: September 03, 2016, 04:24:51 pm
content: Quote from: Simon on September 03, 2016, 03:39:13 pmDunno how this requirement narrowed down your choice to particularly NTC...

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 04:25:49 pm
content: Well that an the fact i've not used I2C yet and i have a customer in a hurry for a quote and i expect they want a prototype as soon as possible.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 04:31:56 pm
content: I am looking for an instrumentation amplifier to buffer my input and while I am at it remove some of DC offset from my thermistor. If I am using the 1.1 V reference in the AVR I will end up with 380 mV at 50 degrees. I only need to measure up to 42 1/2 degrees C so I could take that 380 mV away with the instrumentation amplifier and increase my dynamic range. I don't need any gain which this particular amplifier seems to be okay with but a bit concerned about the grass showing the common mode input voltage of input versus output. I've never seen anything like this before. Thus is part look like it will work?http://www.ti.com/lit/ds/symlink/ina826.pdfI thought I might as well use an instrumentation amplifier instead of a standard op amp as it seems they are all just differential amplifiers which is exactly what I want anyway I want to have an output that is a difference of my input and the offset voltage I intend removing whilst buffering my signal to the ADC input.

author: MarkL
author_rank: Unknown
timestamp: September 03, 2016, 05:17:15 pm
content: Quote from: Simon on September 03, 2016, 03:39:13 pmI've used the 1-wire temperature sensors (DS18B20) extensively. They are accurate (+/-0.5C from -10C to +85C) and easy to use. Don't know about the flame-retardant aspect, but here are some choices for sealed DS18B20 sensors with various mounting options:https://www.adafruit.com/products/381http://www.embeddeddatasystems.com/Environmental-Sensors_c_44.htmlhttp://www.datanab.com/sensors/sensors_1wire.phpDriver libraries are readily available. If your distance requirements are modest you don't need a 1-wire controller and you can drive the sensor(s) directly with the AVR IO pins.

author: tggzzz
author_rank: Super Contributor
timestamp: September 03, 2016, 06:33:24 pm
content: Quote from: Simon on September 03, 2016, 10:30:54 amUnfortunately that idea has occurred to many people, and consider how flash converters are constructed. The problem can be summed up in my best Harold MacMillan voice as "Tolerances, dear boy. Tolerances". Plus my .sig is there for a reason!Having said that, there are techniques (involving adding uncorrelated white noise) that eke out a few extra bits under some circumstances. When asked what he feared, MacMillan famously answered "Events, dear boy, Events".

author: nuno
author_rank: Frequent Contributor
timestamp: September 03, 2016, 06:54:59 pm
content: ATtiny24A has differential reading and gain, so you may already have the needed machinery in the chip to drop the "base voltage" and still get a good resolution. You would need a calibration step on each chip, as the gain is nominal (20x), but stable. The chip also has an internal bandgap, but on this particular AVR ("new generation") I'm not sure it's stable enough over temperature - but an ATtiny26 (not an ATtiny261) probably is.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 07:38:39 pm
content: Ah and I even checked for that and didn't see it. Yes i could use the diferential inputs of the internal ADC and do the same. I wonder what the input impedence is as a 10K thermistor with a 25K pull up may have a bit too much internal impedence.

author: Simon
author_rank: Unknown
timestamp: September 03, 2016, 08:12:30 pm
content: Although I'll loose half the scale as now it's a 9bit ADC not a 10 bit one because it has to represent values with a sign. My values will almost always be positive loosing a whole half of the range.

author: nuno
author_rank: Frequent Contributor
timestamp: September 03, 2016, 11:44:20 pm
content: Quote from: Simon on September 03, 2016, 08:12:30 pmI think it supports both modes, bipolar and unipolar on differential conversion - read that part of the datasheet carefully, and check the fields in the ADC registers. But anyway, you could just give it a "base voltage" that is higher than your desired one (your base + half of your interval of interest) and still use the full 10 bits of the ADC.

author: Simon
author_rank: Unknown
timestamp: September 04, 2016, 06:26:26 am
content: Yes indeed it does, after a lot of searching, now why didn't they put that in the initial description.......

author: Howardlong
author_rank: Super Contributor
timestamp: September 04, 2016, 07:12:42 pm
content: Has the cabling been specified yet? And at what distance? And the consequences of noise picked up on that line? What is the operating temperature range?So far, without further info, it sounds like the amount of time you might spend coming up with an analogue solution could be solved with an off-the-shelf open source library and a 1-wire (possibly even parasitic power) solution. 1-wire can work over several 100s of meters over CAT5, and you can certainly get pyro-style as well as flame retardant CAT5 if required.

author: Simon
author_rank: Unknown
timestamp: September 04, 2016, 07:15:09 pm
content: Err the sensor previously linked to specifically says it's not for corosive environments. Others are not suitable. It's only a few centimetres just to get the sensor out of the enclosure. Plenty of filtering will go on.

author: SeanB
author_rank: Super Contributor
timestamp: September 04, 2016, 07:37:14 pm
content: Major problem with your approach is that the ADC has to be both linear and monotonix, which in a MCU integrated one is not going to happen, unless you are willing to sleep the MCU and do the conversion, then wake again on IRQ after conversion. This will reduce the noise by a lot, but will not make the on chip converter any more linear or monotonic.Best is to use a PT100 film unit in a probe, which is available off the shelf in a PTFE sheathed cable unit with stainless steel sensor, 6mm diameter ( ok quarter inch by 1 inch) with any length of cable you want up to 5m. Stick in a Pt100 input stage for 3 wire operation ( either as discrete parts or as a single module, whatever floats your boat, but the module is cheap, good enough and guaranteed to work off the bat) and you get a voltage which the MCU can read easily with good resolution. just do a few samples and use a moving average ( or simply do 20-100 samples and a simple averaging, which is easy to do in a MCU by adding the 8 bit numbers into a 16 bit integer, take 256 samples and then simply lose the lower 8 bits) to get the temperature as a stable value.Basically the input stage off a commercial temperature controller, and as a bonus no calibration required for your application, and will support sensor temps from -50 to +150C with sub 1C accuracy.

author: Simon
author_rank: Unknown
timestamp: September 04, 2016, 07:40:43 pm
content: Yes i would do plenty of software filtering, I have all the time in the world to do it.

author: nctnico
author_rank: Super Contributor
timestamp: September 04, 2016, 08:22:16 pm
content: Quote from: Simon on September 04, 2016, 07:15:09 pmLook athttps://www.sensorshop24.deThey have all kinds of temperature sensors on wires. I recommend using a PT1000 sensor though because you don't need any amplification with a well choosen divider resistor and 12 bit ADC.

author: Howardlong
author_rank: Super Contributor
timestamp: September 04, 2016, 08:26:45 pm
content: Quote from: Simon on September 04, 2016, 07:40:43 pmHang on, I thought this was urgent!? ;-)QuoteAre you looking for a ready-made flame redardant cable with the sensor already fabricated into it on the end, or are you looking to have a custom assembly?Anyway, I realise it's of no use to you for this application, but I did do a little test on a parasitic 1-wire DS18B20-PAR just now using a (ahem) 13A 50m mains extension reel. Worked a treat.And no, I do not stick screwdrivers into mains outlets everyday of the week.

author: Simon
author_rank: Unknown
timestamp: September 04, 2016, 08:46:11 pm
content: Quote from: Howardlong on September 04, 2016, 08:26:45 pmI mean the uC has all the time in the world to do filtering and everaging. As things stand I have 20 to 50 bits of resolution per degree C so I'm quite happy with a thermistor and analgue input.

author: nuno
author_rank: Frequent Contributor
timestamp: September 04, 2016, 09:35:40 pm
content: Quote from: Simon on September 04, 2016, 08:46:11 pmI guess you meant counts and not bits, right?

author: Marco
author_rank: Super Contributor
timestamp: September 04, 2016, 09:51:22 pm
content: Quote from: SeanB on September 04, 2016, 07:37:14 pmMonotonic yes, but linearity not necessarily. Depending on the application you might be satisfied with having high INL but still wanting high resolution.Quote from: tggzzz on September 03, 2016, 06:33:24 pmIt has to be uncorrelated, it doesn't have to be noise. In fact if it's a known signal you can get extra bits faster than if it's noise.

author: Simon
author_rank: Unknown
timestamp: September 05, 2016, 05:15:00 am
content: Quote from: nuno on September 04, 2016, 09:35:40 pmYes

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 05, 2016, 06:27:41 am
content: Step 1. Reduce range.Only use what you need, no more!This applies toEVERYTHING, by the way -- not just a voltage or temperature as in this case, but to analog inputs (V/I range, protection), digital inputs (logic high/low, protection), bandwidth / frequency response / bit rate (at inputs, outputs, internal nodes, whatever), dynamic range (noise level, number of bits computed) and more.Mark with chalk and cut with an axe!(This isn't absolute, as it depends on what's handy and cheap (a 32-bit ARM "axe" is pretty darn cheap these days, even when you only need an 8-bit butterknife). Engineering is comprehensive, and the best solution is the one that meets all specs, including time and cost!)So what to do here?First, what's the cheapest and easiest approach?- NTC thermistors have high tempco (and only modest uncertainty -- kind of marginal for present purposes, really). That sounds good for starters.- Make a voltage divider. Over the full NTC range, this won't give the best precision (readings bunch together at very low and very high temperatures), but for R_pullup = R25 (i.e., the thermistor's nominal value at 25C), precision is maximized in the middle (around 25C), which is ideal for a limited range.- Amp up the signal. Put an op-amp in front, to subtract the offset (it'll be around VREF/2) and magnify the difference. Use a good DC-stable op-amp. Chopper amps (Vos < 50uV, typically under 1MHz GBW -- still way more than needed here!) are available with low current consumption, at cheap prices.- Convert it as normal. You can -- nay, should -- still do at least a little digital filtering. You start by filtering the analog signal (maybe with a basic RC(RC) section) to the bandwidth required (for a thermostat, 10Hz is more than enough!), which ensures the analog signal being sampled, isn't moving around much between samples. This makes the analog voltage consistent, so you know any sample-to-sample errors will be due to the converter. Filter this with something basic, like a 1st or 2nd order IIR filter.You can sample at a pretty high rate, like kHz, and accumulate a few extra bits of precision. But don't put too much trust in these, because the distance between steps is not guaranteed to be very good. That is, the analog voltage change between ADC steps 0x20 to 0x21, need not be the same as steps 0x7D to 0x7E, or anywhere else (this is the differential error DNL).The analog signal might not be changing all that frequently, either; if it's sitting stable on one ADC code, then you can't get extra precision no matter how many times you oversample that one code! You can intentionally add noise (often not white noise, but something that has a long period against the ADC sample rate) to dither between values. If the noise has an even distribution over several codes' range, then those codes will be represented equally often, except for the ones at the ends of the spread, which vary with input.A trick might be to set the ADC sample rate at 1kHz, and set a PWM timer for 1.01kHz (or whatever's closest to 10Hz away from the actual ADC sample rate). Run it through a good solid filter, so the square wave gets filtered down to a triangle or quasi-sinusoidal shape. Use a voltage divider to shrink it to a few mV, then add this into the ADC input. Now on the digital side, if you accumulate samples for 100ms and use that as a decimating filter (i.e., save the accumulator value, then reset it, every 100ms; thus generating an internal 10Hz sample rate), the dithering will have gone through a full 360 degree rotation with respect to the sample rate, so you've sampled every possible dither value, not just random ones. Nice!- This general plan can be tweaked and expanded, however you like. Swap out thermistor for semiconductor sensor (LM34?). Or Pt1000 sensor and suitable adjustments to the analog circuit (divider with compensation resistors). Or thermocouple plus cold junction compensation (there are ICs that handle this all for you).Tim

author: Simon
author_rank: Unknown
timestamp: September 05, 2016, 06:33:54 am
content: attached is my spreadsheet. Amplification is not neccesary, if i pull up to 5V and use the 1.1V reference then I automatically ignore the pull up headroom. All I need do then is subtract the offset.

author: Psi
author_rank: Super Contributor
timestamp: September 05, 2016, 06:58:16 am
content: If the signal to measure is static or very low frequency you could generate a 16/32bit pwm dac. Feed it into the AVRs analog comparator along with your sample voltage and then search for the transition point in software.Bam.... Software adcIm not saying its a good solution. But it is pretty funny

author: nuno
author_rank: Frequent Contributor
timestamp: September 05, 2016, 07:30:59 am
content: Quote from: Simon on September 05, 2016, 06:33:54 amIf you're planning on using ATtiny24, I advise you to check what's the internal 1.1V Vref stability over temperature in your range of interest.

author: Simon
author_rank: Unknown
timestamp: September 05, 2016, 11:49:45 am
content: Hm yes 1-1.2V, not great almost a 10% shift either way. Might use an external reference. or run the thermistor from a 10V zener.

author: wraper
author_rank: Unknown
timestamp: September 05, 2016, 12:02:04 pm
content: As long as NTC power is used as voltage reference for ADC (or vice versa), Their tolerance and long term stability do not matter. Everything will scale accordingly and the value read by ADC won't change. Stable ratio is all need to be kept. So I suggest using resistive divider as a voltage reference.

author: nuno
author_rank: Frequent Contributor
timestamp: September 05, 2016, 12:24:08 pm
content: 1 - 1V2 is Vref voltage variation from chip to chip, stability over temperature is another thing.As wrapper suggests, if you use the ADC Vref for the NTC resistor divider you'll be taking ratiometric readings and Vref can change without impact. But if you use the Vref from the AVR, you'll have to buffer it (at least in the older generation, they had nominal 32K output resistance).

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 05, 2016, 06:08:37 pm
content: Note that ADC performance is degraded at lower Vref.ATmega/tiny ADCs are shitty enough to begin with, at 5V!Tim

author: Simon
author_rank: Unknown
timestamp: September 05, 2016, 06:47:33 pm
content: Well i can pull a Vref from the 5V supply to the AVR also used to power the NTC so ratiometric. I was thinking 2.5V for the pure simplicity of using 2 resistors of the same value.

author: Simon
author_rank: Unknown
timestamp: September 05, 2016, 07:10:11 pm
content: Even better idea. stuff the internal amp in the AVR, I'll stick with my instrumentation amplifier and amplify the result so that I recover the full 5V range, that also allows freedom of choice in the pull up and I've been able to rough linearize the counts per celcius to 9 or 10 (and can amplify by 2.5 easily getting 25 all round).

author: danadak
author_rank: Super Contributor
timestamp: September 06, 2016, 01:16:49 am
content: If you work with Cypress PSOC 5LP or 3 family, you get an Arm or 8051 core respectively, 20 bitdiff A/D with gain front end, onchip Vref, several OpAmps, rout-ability......plus DSP to filterthe signal path, FIR, IIR. Tons of logic, either GUI drag and drop, or use Verilog to roll yourown from scratch. COM, LCD......Do the error math, taking an 8 bit, then digitizing again to interpolate, you will wind up gettingless than 8 bits when all is said and done.Regards, Dana.