Author Topic: Microchip ADC  (Read 9701 times)

0 Members and 1 Guest are viewing this topic.

Offline RRTopic starter

  • Contributor
  • Posts: 30
  • Country: cz
Microchip ADC
« on: February 03, 2014, 10:52:50 am »
I choose for my project PIC18f25k80 - http://ww1.microchip.com/downloads/en/DeviceDoc/39977f.pdf
and use 3.3V supply and want to use all 12bit resolution
in characteristics is for 12bit Vref>3V
It 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?


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #1 on: February 03, 2014, 11:44:24 am »
-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.
================================
https://dannyelectronics.wordpress.com/
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7369
  • Country: nl
  • Current job: ATEX product design
Re: Microchip ADC
« Reply #2 on: February 03, 2014, 12:39:16 pm »
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.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21657
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Microchip ADC
« Reply #3 on: February 03, 2014, 12:48:58 pm »
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 reference really 1.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 ADCs suck.  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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #4 on: February 03, 2014, 12:55:19 pm »
-can't tell what they mean about the reference (p.579).  What...-

rather than getting si frustrated, take a class in EE 101.
================================
https://dannyelectronics.wordpress.com/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26891
  • Country: nl
    • NCT Developments
Re: Microchip ADC
« Reply #5 on: February 03, 2014, 02:33:36 pm »
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #6 on: February 03, 2014, 07:06:04 pm »
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.
================================
https://dannyelectronics.wordpress.com/
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21657
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Microchip ADC
« Reply #7 on: February 03, 2014, 09:24:08 pm »
-can't tell what they mean about the reference (p.579).  What...-

rather than getting si frustrated, take a class in EE 101.

So*

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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline RRTopic starter

  • Contributor
  • Posts: 30
  • Country: cz
Re: Microchip ADC
« Reply #8 on: February 03, 2014, 11:30:45 pm »
ok so what i have is

0-4V input signal that i want measure with 1mV resolution and <5mV accuracy

on input i plan just use this simple frontend



I 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
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21657
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Microchip ADC
« Reply #9 on: February 04, 2014, 12:10:46 am »
You will need a very high precision voltage reference to achieve that accuracy, and 12 bits is absolute minimum: an ideal ADC will just achieve 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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline lewis

  • Frequent Contributor
  • **
  • Posts: 704
  • Country: gb
  • Nullius in verba
Re: Microchip ADC
« Reply #10 on: February 04, 2014, 12:47:12 am »
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 this http://electronics.stackexchange.com/questions/30370/fast-and-memory-efficient-moving-average-calculation

Code: [Select]

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 errors
int 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 function
     int iir;
     int prev_tmp = *prev;                          //store copy of pointer to decrease code size
     iir = ((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' value
     return prev_tmp/32;
}


//get voltage and perform IIR
//call from fast loop - needs LOTS of calls to get a decent result
int get_volts() {
     int res;
     res = sample_adc(input);                           //get ADC value
     res = do_iir(&prev_volts, res, 4);                 //do IIR on it...
     return res;
}



I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #11 on: February 04, 2014, 12:49:54 am »
Quote
0-4V input signal that i want measure with 1mV resolution and <5mV accuracy

That 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #12 on: February 04, 2014, 12:53:08 am »
Oversampling fundamentally doesn't solve the problem. And in cases where a control loop is involved, oversampling may introduce instability.

Code: [Select]
    //result = oldresult + (( newresult - oldresult) / hardness )
A faster way is to do this:

Code: [Select]
  result += (newresult - result) / hardness;
For some compilers, you may have to force a type conversion.
================================
https://dannyelectronics.wordpress.com/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26891
  • Country: nl
    • NCT Developments
Re: Microchip ADC
« Reply #13 on: February 04, 2014, 08:06:14 am »
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline arcom

  • Contributor
  • Posts: 42
  • Country: hr
    • Arc's Lab
Re: Microchip ADC
« Reply #14 on: February 04, 2014, 09:12:10 am »
K80 series PICs have a problem with the 12-bit ADC. You can find the description and workaround in the K80 silicon errata.
Quote
A/D Offset
The A/D may have high offset error, up to a maximum of ±25 LSBs; it can be used if the A/D is calibrated for the offset.

Work around
Calibrate for offset in Single-Ended mode by connecting A/D +ve input to ground and taking the A/D reading. This will be the offset of the device and can be used to compensate for the subsequent A/D readings on the actual inputs

Basically, 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.
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7369
  • Country: nl
  • Current job: ATEX product design
Re: Microchip ADC
« Reply #15 on: February 04, 2014, 10:23:03 am »
K80 series PICs have a problem with the 12-bit ADC. You can find the description and workaround in the K80 silicon errata.
Quote
A/D Offset
The A/D may have high offset error, up to a maximum of ±25 LSBs; it can be used if the A/D is calibrated for the offset.

Work around
Calibrate for offset in Single-Ended mode by connecting A/D +ve input to ground and taking the A/D reading. This will be the offset of the device and can be used to compensate for the subsequent A/D readings on the actual inputs

Basically, 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.
I 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.
 

Offline lewis

  • Frequent Contributor
  • **
  • Posts: 704
  • Country: gb
  • Nullius in verba
Re: Microchip ADC
« Reply #16 on: February 04, 2014, 11:18:56 am »
Yep, some PICs are piss poor. Always check the errata!
I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.
 

Offline arcom

  • Contributor
  • Posts: 42
  • Country: hr
    • Arc's Lab
Re: Microchip ADC
« Reply #17 on: February 04, 2014, 11:55:45 am »
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.
 

Online AndyC_772

  • Super Contributor
  • ***
  • Posts: 4223
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Microchip ADC
« Reply #18 on: February 04, 2014, 11:57:07 am »
This one is particularly bad, though...

Quote from: Microchip errata
The 12-bit A/D performance is outside of the
data sheet’s A/D Converter specifications.
When used as a 12-bit A/D, the possible issues
are: high offset error, up to a maximum of
±25 LSBs at 25°C, ±30 LSBs at 85°C, 125°C
and -40°C; high DNL error, up to a maximum of
+6.0/-4.0 LSBs; and multiple missing codes, up
to a maximum of twenty. Users should evaluate
the 12-bit A/D performance in their application
using the suggested work around below. See
Table 3 for guidance specifications

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microchip ADC
« Reply #19 on: February 04, 2014, 12:04:12 pm »
Quote
I'm waiting for dannyf to tell me that we just don't understand datasheets,

I think I said that YOU didn't understand the datasheets and I suspected that you made up your story about the library issue.

Quote
and Microchip is doing everything perfectly.

They are anything but.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf