Microchip ADC - Page 1
Forum section: electronics / general

author: RR
author_rank: Contributor
timestamp: February 03, 2014, 10:52:50 am
content: I choose for my project PIC18f25k80 -http://ww1.microchip.com/downloads/en/DeviceDoc/39977f.pdfand use 3.3V supply and want to use all 12bit resolutionin characteristics is for 12bit Vref>3VIt have two internal references 2V and 4V.Will that 4V reference work?What will happen when i use <3V?will tl431 set to 3V be better option?

author: dannyf
author_rank: Super Contributor
timestamp: February 03, 2014, 11:44:24 am
content: -will tl431 set to 3V be better option?-depending on if you are aiming for accuracy or resolution, and which 431 you are talking about.

author: tszaboo
author_rank: Super Contributor
timestamp: February 03, 2014, 12:39:16 pm
content: The Vref has to be smaller than your supply voltage. Even if you would use a 4V reference, the input voltage cannot be higher than the supply voltage, which means you loose 1V from the range.If your measurement is ratiometric, then use the power supply for your reference. The TL431 is totally inadequate for anything above 6-8 bits. It could have 8LSB/K drift.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 03, 2014, 12:48:58 pm
content: I can't tell what they mean about the reference (p.579). What is "12 bit resolution"? Am I guaranteed to have true 12 bit accuracy for Vdd > 3V or something?Is the referencereally1.024V like it says elsewhere in the datasheet? p.559 says "absolute accuracy" is <= 1/2 LSB, but accurate to what? Is it actually 1.02400000V??? Can you not just *say* so?! And what is this "resolution"? Is the reference actually resolved to some ratio of Vdd? What the hell?Even if it were possible to make sense of their retarded specifications, you can safely assume that onboard ADCssuck. In general, if you need more than 10 bit resolution, guaranteed, you do it with an external ADC. Hopefully the SPI port works as specified.Ugh, reading this datasheet gives me even less confidence in PICs than I have in ATmega/AVR chips. I've also heard stories about Microchip's awful Errata for various PIC series chips. Like, USARTs that say certain things in the body, yet utterly fail in practice. As mentioned in the errrata. With absolutely no workaround. Riiight.Ugh.Buy MSP430 instead, I guess??Tim

author: dannyf
author_rank: Super Contributor
timestamp: February 03, 2014, 12:55:19 pm
content: -can't tell what they mean about the reference (p.579). What...-rather than getting si frustrated, take a class in EE 101.

author: nctnico
author_rank: Super Contributor
timestamp: February 03, 2014, 02:33:36 pm
content: Rule of thumb: don't expect to get full resolution from a Microchip part. If you want accuracy you'll need an external ADC from Analog devices, TI, etc.

author: dannyf
author_rank: Super Contributor
timestamp: February 03, 2014, 07:06:04 pm
content: You always get the same resolution.your effective or noise free resolution may change, Microchip or otherwise.his issue is confusing resolution with accuracy. And no amount of non-Microchip outboard adv can solve that.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 03, 2014, 09:24:08 pm
content: Quote from: dannyf on February 03, 2014, 12:55:19 pmSo*Do you ever have anything positive to say? Looking at your posting history, I guess not.You obviously have no knowledge nor desire to understand my experience level.By the way, there's this forum thing where you put [ quote ] brackets around text, so people don't have to guess what part of your post is copied.I guess after a thousand posts, the moderators have decided you aren't an imminent threat, fortunately I believe I saw a "block user" option somewhere on this forum... awesome!Tim

author: RR
author_rank: Contributor
timestamp: February 03, 2014, 11:30:45 pm
content: ok so what i have is0-4V input signal that i want measure with 1mV resolution and <5mV accuracyon input i plan just use this simple frontendI just choose Microchip because i have experience with it and pickit too. But iam not against different options just dont want to buy expensive programmer and then program 5 chips and done.What i need from MCU is 12-13 I/O+SPI+2xADC,small EEprom,~8KB+ rom, work on 3.3V in 28soic or smaller and price <$3

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 04, 2014, 12:10:46 am
content: You will need a very high precision voltage reference to achieve that accuracy, and 12 bits is absolute minimum: an ideal ADC willjustachieve that. 14 or even 16 bits might be better, and probably not much different in price as long as the required sample rate is modest (under 100k or so?).An LM358 has max 3mV input offset, will not pull all the way to GND (it's a "single supply" type, but the amount of current it can sink near ground is near zero), and will only pull up within 1-2V of the supply (so a 5V or greater positive supply is required). A true R2R amp like TLV2371 (if not for its max 6mV offset) might do better near the rails (and could run on 3.3V), but again you still won't get all the way to 0mV. A precision type op-amp is required to do buffering or amplification here, probably with extra power supply range. (which doesn't need to be much; a -0.5V supply would be enough, though at that point, you might as well go with -3.3V from a charge pump and use a normal rather than R2R type opamp).But almost all ADCs draw very little if any DC current from their inputs; why use an op-amp at all? Do you require analog bandwidth comparable to the sample rate?Other options include dithering (out-of-band or noisy dithering) and averaging, or more involved methods (if a DAC is handy, subtractive dithering or sigma-delta). These are suitable if the required bandwidth is much lower than the available sample rate.Tim

author: lewis
author_rank: Frequent Contributor
timestamp: February 04, 2014, 12:47:12 am
content: You can steal some extra bits from a 10bit ADC for free. The internal acquisition noise of the converter and any external gaussian noise from buffering op-amps will tend to wobble about the LSB. Sample and average the result enough times and you can extend the resolution up to 12-14 bits at a push, as long as you can cope with one or two results per second. Even if the noise is not gaussian you can make it almost random by sampling at irregular (but still very frequent) intervals.How? Filtering! An IIR filter is what you need. Here's my implementation of thishttp://electronics.stackexchange.com/questions/30370/fast-and-memory-efficient-moving-average-calculationCode:static int prev_volts; // IIR static global variable//IIR filter - new skool MAF which is MUCH better//uses signed integers because of intermediate negative values//accepts 10-bit values maximum - this function multiplies by 32 and divides at the end to increase resolution and decrease rounding errorsint do_iir (int *prev, int current, unsigned char hardness) {//result = oldresult + (( newresult - oldresult) / hardness )//info here: http://electronics.stackexchange.com/questions/30370/fast-and-memory-efficient-moving-average-calculation//hardness specified as bumber of bit shifts, eg desired hardness of 256 means we pass 8 to this functionint iir;int prev_tmp = *prev; //store copy of pointer to decrease code sizeiir = ((current*32) - prev_tmp)>>(hardness-1); //don't quite divide all the way yet, we need to check if the number is going to be odd to round the result correctly//shifting right by 'hardness-1' is the same as 'dividing by hardness/2'if(lo(iir).B0) iir++; //if we're going to need to round up (if it's an odd number), increment.prev_tmp = (iir/2) + prev_tmp; //divide by 2 to get the full IIR hardness*prev = prev_tmp; //save the new 'previous' valuereturn prev_tmp/32;}//get voltage and perform IIR//call from fast loop - needs LOTS of calls to get a decent resultint get_volts() {int res;res = sample_adc(input); //get ADC valueres = do_iir(&prev_volts, res, 4); //do IIR on it...return res;}

author: dannyf
author_rank: Super Contributor
timestamp: February 04, 2014, 12:49:54 am
content: QuoteThat means an adc with 4v/1mv = 4000 discrete steps. or 12-bit adc. However, those adcs are typically not accurate with in 8 lsb -> 8mv.There are higher resolution onboard adc, or outboard adc with more flexibility.Another approach is to use a PGA -> look into some AVRs in that case.

author: dannyf
author_rank: Super Contributor
timestamp: February 04, 2014, 12:53:08 am
content: Oversampling fundamentally doesn't solve the problem. And in cases where a control loop is involved, oversampling may introduce instability.Code://result = oldresult + (( newresult - oldresult) / hardness )A faster way is to do this:Code:result += (newresult - result) / hardness;For some compilers, you may have to force a type conversion.

author: nctnico
author_rank: Super Contributor
timestamp: February 04, 2014, 08:06:14 am
content: That is not oversampling, that is filtering. In oversampling you add 4 samples and divide the result by 2 (or 16 samples and divide by 4). But that only works if there is enough noise.Looking at the schematic: get rid of the diodes. They will introduce errors because of their leakage current. Also get rid of the opamp because it introduces offset. I'd use a resistive divider to get the signal into the range of the ADC. Capacitor C9 can stay. The ADC will have ESD clamp diodes so make sure R1 is high enough to stay within the limits of the clamping diodes.

author: arcom
author_rank: Contributor
timestamp: February 04, 2014, 09:12:10 am
content: K80 series PICs have a problem with the 12-bit ADC. You can find the description and workaround in theK80 silicon errata.QuoteBasically, if you really need 12-bit resolution, get a different PIC or use an external A/D converter. I have used the same PIC before but A/D measurements weren't critical so I have just dropped the resolution to 10 bits with offset calculation and it worked fine.

author: tszaboo
author_rank: Super Contributor
timestamp: February 04, 2014, 10:23:03 am
content: Quote from: arcom on February 04, 2014, 09:12:10 amI just love these Microchip datasheets. Datasheet: Maximum offset error: +/-9LSB.Errate: Maximum offset error: +/-25LSB. DNL is 2 times more than datasheet states. Gain error is again two times more.I'm waiting for dannyf to tell me that we just don't understand datasheets, and Microchip is doing everything perfectly.

author: lewis
author_rank: Frequent Contributor
timestamp: February 04, 2014, 11:18:56 am
content: Yep, some PICs are piss poor. Always check the errata!

author: arcom
author_rank: Contributor
timestamp: February 04, 2014, 11:55:45 am
content: Not only for PICs but all other MCUs. I haven't seen a single microcontroller that doesn't have an errata attached to its documentation.

author: AndyC_772
author_rank: Super Contributor
timestamp: February 04, 2014, 11:57:07 am
content: This one is particularly bad, though...Quote from: Microchip errata

author: dannyf
author_rank: Super Contributor
timestamp: February 04, 2014, 12:04:12 pm
content: QuoteI think I said that YOU didn't understand the datasheets and I suspected that you made up your story about the library issue.QuoteThey are anything but.