Author Topic: Increase resolution on microcontroller ADC  (Read 6155 times)

0 Members and 1 Guest are viewing this topic.

Offline mitrynicolaeTopic starter

  • Contributor
  • Posts: 45
  • Country: ro
Increase resolution on microcontroller ADC
« on: October 08, 2016, 04:15:54 pm »
Hello all,

I have a simple yet complicated electronics problem. I want to build a power supply. For the current measurement part i will use the voltage drop technique. On a 10 amp output I want 1 volt drop across an internal resistor. This means that I need to use 100 miliohm resistor (0.1 ohm). Is this correct? Also from my calculation I would need a 10 W resistor, but since I don't want this resistor to get warm at all I will use an 100 W resistor. Further I will use an opamp to increase the output voltage from 1 volt (the drop voltage) to 5 volts (in other words for 5 A on output, the opamp will output 2.5 V).
The problem that I have is that the microcontroller only has 10 bits resolution, and reading 5 volts on 1024 bits leads to 4.882mV per bit which actualy means that on each bit I will actually read approximately 10mA. Because I want to adjust the output current at the mA level, the described scenario is not good enough. So I thought to use 2 ADC on the microcontroller and split the max voltage in two like follows:
if the voltage is between 0 and 2.5 volts, using an opamp I will read 5 volts (max) on output.
if the voltage exceed 2.5 volts (and max 5 volts) I need to read 5 volts (max) on output.
So actually, if you didn't follow me on this point. If the output is lower than 2.5 volts the first ADC will read the current voltage value * 2 and the second ADC will read 0. And if the value exceed 2.5 volts the first ADC will read 5 volts and the second ADC will read the (current voltage value - 5 volts) * 2.
The second problem that I found when I wrote this lines is that between reading first ADC and second ADC the values might change and I can get incorrect data. Anyway, how can I perform the above operation (split the 5 volts in 2 pairs of 0-5 volts as described above) ?

If any of you have any idea of how to increase resolution (using ONLY the internal 10 bits resolution ADC of the MCU) you can share it, I am open to any suggestion. I don't want to use any external ADC of any kind.

Kind regards,
Nicolae Mitroi.
 

Offline beeryt

  • Newbie
  • Posts: 6
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #1 on: October 08, 2016, 04:59:31 pm »
You have to balance resolution and range. If you dropped your range (5A max) you would have a greater resolution (<10mA). Many multimeters have a switch that selects a different internal resistor depending on the desired resolution. This is why the 2mA range maxes out at 2mA.
 

Offline CraigHB

  • Regular Contributor
  • *
  • Posts: 227
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #2 on: October 08, 2016, 05:22:11 pm »
To measure currents like that you'd typically use a current sense resistor around ten mOhms rather than a hundred.  Otherwise you need a prohibitively large resistor to handle the resulting power loss.  For example a 2W current sense resistor of 10 mOhms can handle about 14 Amps.

There is the issue of noise sensitivity using the higher gains required for a lower value current sense resistor.  The times I've used an ammeter in a project I've not had any trouble using only a filter on the amp output.  There's also the option of Hall Effect current sense chips.  They have some great advantages like very low insertion loss; http://www.allegromicro.com/en/Products/Current-Sensor-ICs.aspx

I'm sure there's a way to utilize two ten bit ADCs to provide higher resolution, but I don't have any suggestion.  It's probably going to be a bit convoluted.  If it were me, I would just go with an MCU that provides a 12 bit ADC.  In fact it seems 10 bit ADCs in micro-controllers are kind of being superseded at this point by 12 bit ADCs.


« Last Edit: October 08, 2016, 05:44:22 pm by CraigHB »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #3 on: October 08, 2016, 06:01:55 pm »
First of all, you don't want to put the shunt resistor in the return lead.  It has a tendency to lift your project ground above every other ground.  That's why they invented high side current sense amplifiers. 

Your shunt resistor is far too big.  In the industrial world, we use 50 mV shunts.  At full scale, whether 1 Amp or 1000 Amps, the voltage drop across the shunt is 50 mV.  You would use something on the order of 5 milliohms and a 1W resistor would be more than adequate.
 
With your op amp solution, you are proposing to get accuracy beyond what I would believe is possible.  You could probably calibrate around it but there's no way your circuit will behave like 1 part in 214.  Why don't you just use a 14 bit ADC?  There pretty reasonable ($30) and easy to interface.

You would still want to scale the output of the current sense amplifier with an op amp.  Everything you want to know about scale and offset is in "Op Amps For Everyone" around section 4.3
http://web.mit.edu/6.101/www/reference/op_amps_everyone.pdf

In any event, the reference book will show you how to do whatever you want with scale and offset even if you pursue your existing approach.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14072
  • Country: de
Re: Increase resolution on microcontroller ADC
« Reply #4 on: October 08, 2016, 06:41:11 pm »
The shunt should smaller, more like 10 or 5 mOhms. So a 50-100 mV drop at full scale.

If the measurement does not need to be fast, there are quite some cheap sigma delta ADC available, that allow direct reading of such small voltages. A cheap one is the MCP3421 at usually less than $3. It still gets you 18 Bit resolution for a +-250 mV range and a differential input (to use 4 wire connection of the shunt). Amplification is possible, but it still does not give you more than the 10 Bit accuracy of the ADC.

The shunt in the return lead is not that bad - it depends on the circuit. Having a high side shunt with special high side current measurement amplifier can also be tricky.
 

Offline Microcheap

  • Regular Contributor
  • *
  • Posts: 248
  • Country: 00
Re: Increase resolution on microcontroller ADC
« Reply #5 on: October 08, 2016, 07:15:46 pm »
I think that what you are looking for is technique called oversampling and decimation. Basically, it consist in using the idle processing power of your microcontroller to take a greater number of samples from the ADC and do some calculations to effectively get a higher resolution result value.

Have a look at these application notes, they should have most of the information that you'll need:
https://www.silabs.com/Support%20Documents/TechnicalDocs/an118.pdf
http://www.atmel.com/images/doc8003.pdf
http://www.actel.com/documents/Improve_ADC_WP.pdf
 

Offline CraigHB

  • Regular Contributor
  • *
  • Posts: 227
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #6 on: October 09, 2016, 02:08:33 pm »
Yes low side amplifiers are easier to implement, but supply ground can not be shared with output ground or it bypasses the sense resistor. For high side sensing an amplifier is required that can handle DC offset which makes things more involved.  High side sensing is generally better, but low side sensing can be used in some situations.

In the OP he mentioned he did not want to use an external ADC.  I can understand that since it's kind of ridiculous to use an external one when the MCU provides something adequate.  As mentioned it's a trade-off for range versus resolution.  That ten bits can get pretty coarse when spread out over a larger range.  12 bits is better but can still get coarse if range is large.  There might be a way to range things in software.  Take a sample to determine range then vary ADC references to take a second sample with a more narrow range providing better resolution.
 

Offline bktemp

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: de
Re: Increase resolution on microcontroller ADC
« Reply #7 on: October 09, 2016, 03:01:33 pm »
In the OP he mentioned he did not want to use an external ADC.  I can understand that since it's kind of ridiculous to use an external one when the MCU provides something adequate.
External ADCs are often better than internal ones, even if they have the same resolution. That's because a lot of noise gets injected into the ADC if it is on the same die as the microcontroller.
Often the INL and DNL is quite bad especially when there are no seperate supply and reference pins for the ADC (I once measured the ADC on a PIC and it made a huge improvement on INL and DNL when using external reference pins instead of AVcc/Avss). Because of the bad DNL, oversampling is often useless (unless you add quite some large noise or other modulation waveforms to cover multiple steps) because the steps aren't even and you won't notice that unless you do a full characterisation of the transfer curve.

Quote
As mentioned it's a trade-off for range versus resolution.  That ten bits can get pretty coarse when spread out over a larger range.  12 bits is better but can still get coarse if range is large.  There might be a way to range things in software.  Take a sample to determine range then vary ADC references to take a second sample with a more narrow range providing better resolution.
Yes, using multiple ranges is probably the easiest solution. Simply add a gain stage in front of the ADC:
If the ADC value is below 95, increase the gain by 10. Now the value will be somewhere between 0-950. The resolution has increased from 10mA to 1mA for the 0-1A range. If you measure more than 1020, discard the value, switch back to 1x gain and measure again. Using this method you can show 3 digits: Either xxxmA or x.xxA (maybe you need to add xx.xA if you want to go slightly above 10A).
 

Offline CraigHB

  • Regular Contributor
  • *
  • Posts: 227
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #8 on: October 09, 2016, 03:45:56 pm »
That's because a lot of noise gets injected into the ADC if it is on the same die as the microcontroller.

Yes micro-controllers can be noisy due to the way they operate.  Current demand fluctuates with each clock pulse producing a lot of noise.  For the ammeters I've done I've not found it a problem to use the MCU's ADC.  I can get stable readings with only a filter on amplifier output.  Though for more exacting measurements where it's not possible to filter or average it can be a problem.  In that case an external ADC might work a lot better.

Personally I'd just use an external 16 bit ADC if that's what it took to do the job, but the OP does not want to go that route.  Sometimes one can get stubborn with a particular design.  It's a pitfall I've been guilty of a few times.
« Last Edit: October 09, 2016, 03:47:48 pm by CraigHB »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Increase resolution on microcontroller ADC
« Reply #9 on: October 09, 2016, 04:11:20 pm »
I think that what you are looking for is technique called oversampling and decimation. Basically, it consist in using the idle processing power of your microcontroller to take a greater number of samples from the ADC and do some calculations to effectively get a higher resolution result value.

Have a look at these application notes, they should have most of the information that you'll need:
https://www.silabs.com/Support%20Documents/TechnicalDocs/an118.pdf
http://www.atmel.com/images/doc8003.pdf
http://www.actel.com/documents/Improve_ADC_WP.pdf

That last attachment is quite interesting.  To achieve oversampling and decimation, we may need to ADD noise to the circuit.  The process requires a LSB dither in the samples but the sample itself can't change by more then 1/2 LSB during the sample interval.  If we don't have enough white noise from the circuitry, we have to add some!

if the requirement is 14 bits, the op amps will need to accurately scale to 1 part in 214 and that brings along some pretty interesting requirements for the gain resistors.

The good news is that the op amps will have a low output impedance and this is usually required for driving uC ADCs.  Some will handle high impedance sources better than others.
 

Offline bktemp

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: de
Re: Increase resolution on microcontroller ADC
« Reply #10 on: October 09, 2016, 04:26:56 pm »
That's because a lot of noise gets injected into the ADC if it is on the same die as the microcontroller.

Yes micro-controllers can be noisy due to the way they operate.  Current demand fluctuates with each clock pulse producing a lot of noise.  For the ammeters I've done I've not found it a problem to use the MCU's ADC.  I can get stable readings with only a filter on amplifier output.  Though for more exacting measurements where it's not possible to filter or average it can be a problem.  In that case an external ADC might work a lot better.
True noise isn't the problem, it can actually help for oversampling when filtering the ADC results. The problem is, the noise is effecting only certain values (like steps between 255<->256, 511<->512, 767<->768), making the ADC transfer function non-monotonic: It misses steps. You won't notice that unless you apply a sawtooth or triangle waveform and record every samples and look at the histogramm (you can also use a sinewave, but it needs some more processing afterwards).

If you need more resolution, oversampling a bad ADC works fine with enough noise, but it does not increase the accuracy. Another important note when using oversampling: It does not work well at both ends of the range! If you add too much noise resulting in ADC values below 0 or above 1023 (for 10bits), the noise will introduce an offset error. So you need to add some margin in the voltage range.
Therefore in this case the best solutions are either using an external ADC with a higher resolution or switching gain, everything else will be more difficult.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16545
  • Country: us
  • DavidH
Re: Increase resolution on microcontroller ADC
« Reply #11 on: October 09, 2016, 10:40:25 pm »
If you need more resolution, oversampling a bad ADC works fine with enough noise, but it does not increase the accuracy.

This needs to be stressed.  Nothing suggested will improve the accuracy because it will not improve the integral nonlinearlity.  So a reading of 512 out of 1024 (10 bits) is not going to be any more accurate than an oversampled reading of 2048 out of 4096 (12 bits) and most microcontroller ADCs are not even as linear as their resolution suggests.  In theory the integral nonlinearity can be calibrated but it is an awful lot of work compared to just using a better ADC.

There are some exceptions like the 16 bit delta-sigma ADC in the C8051F352 microcontroller which actually has 16 bits of linearity to match its 16 bits of resolution.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Increase resolution on microcontroller ADC
« Reply #12 on: October 10, 2016, 12:05:57 am »
definitely go for external ADCs and DACs. you mention 10Bit - i assume you're talking about ATmega ;) the ADC in atmega is good for generic sensing applications  but not for a precise power supply.
 

Online egonotto

  • Frequent Contributor
  • **
  • Posts: 648
Re: Increase resolution on microcontroller ADC
« Reply #13 on: October 10, 2016, 03:57:22 am »
Hi,

i do same trial with an PicoScope 5243A.
There you can choose 8Bit 12Bit till 16Bit resolution.
The generator generates a 1kHz triangle with 20mV p-p.

I measure this signal with several input ranges and several enhanced resolution ranges and several resolution.
The information are in the pictures. So i don't need describe in detail.
There you can see, what enhanced resolution serves in this example.

Best regards
egonotto
 


 

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: nz
Re: Increase resolution on microcontroller ADC
« Reply #14 on: October 12, 2016, 09:05:50 am »
Regarding noise on internal adc's, I'm sure I've read in a PIC datasheet you can put the micro to sleep while the conversion is taking place and the adc complete interrupt wakes it back up when it's done. No noise from the digital side.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf