4

At this moment I am using oversampling to increase my analogread resolution. This in combination with increasing the frequency of the ADC. Is someone able to take a look at it?

#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

int value[100];   // variable to store the value coming from the sensor
int i=0;

void setup() 
{
  Serial.begin(9600) ;
 int start ;
 int i ;

#if FASTADC
 // set prescale to 16 (1MHz)
 sbi(ADCSRA,ADPS2) ;
 cbi(ADCSRA,ADPS1) ;
 cbi(ADCSRA,ADPS0) ;
#endif
}

void loop() 
  { 
  for (i=0;i<100;i++)
  {
   value[i]=Read12bit(0);
  } 
  for (i=0;i<100;i++)
  {
   Serial.println(value[i]);
  } 
  Serial.println();//Some blanks between values
  Serial.println();
  delay(5000);

}


int Read12bit(uint8_t pin){
      int Result = 0;
      analogRead(pin);                      //Switch ADC
      for(int i = 0;i < 16; i++) {          //Read 16 times
        Result = Result + analogRead(pin);  //Sum results 
      }
      Result = (int)Result/4;               //Divide by 4 for 12 bit value
      return(Result);
    }

At this moment the resolution of this oversampled analogread is 12-bits. With a little calculation the time to read will take 0,208milliseconds. If I want to increase my resolution more i.e. 13-bit. This will take the measurement 0,832 milliseconds. This seems rather big, so my question is can I do this in another way?

EDIT Why? I am trying to position multiple linear actuator using multiple arduino's connected via CAN-bus (the arduino's will not communicate with eachother unless an error occures) THe positioning has to be precise (<0.1mm on a 30 cm rod).

Why is 12 or 13 bit accuracy and/or resolution needed?

12 is probably enough. But I just like to find out the boundaries of the equipment :)

What real world processes are being monitored that 0.012% perbit step sizes are not swallowed in the noise of reality?

Probably none 13-bit resolution is probably too high for my application anyways.

Other reason why I like a higher resolution First couple of voltages I cannot use. My sensor gives a 4 to 20mA signal which i convert with resistor to ground.

3
  • Telling us the desired resolution and maximum allowed sampling time would help. Telling us why would help more. ie knowing what you are really trying to do may allow a quite different approach to be suggested or allow a fatal flaw to be identified. || You cannot usually extend ADC bits indefinitely by oversampling with any great expectations of accuracy. Oversampling works on the basis of the variable + noise being linearly randomly distributed across the 'space' at least 1/2 a bit size either side of the true value. And it makes assumptions about ways in which ADC sample and hold .... Jun 18, 2015 at 11:44
  • What desired max sampling time at say 12 bits? Jun 18, 2015 at 14:57
  • as low as possible, I do not want my loop time over 10 ms (with some safety milliseconds build in). More then a millisec for a measurement is too much.
    – KoenR
    Jun 19, 2015 at 7:50

4 Answers 4

4

Yes, you can use an external ADC chip. You can get SPI and I2C ΣΔ ADC chips at 16-bit and higher quite easily.

I often use the MCP3553 which allows 60sps at 22-bit.

4
  • Thanks for the tip. This wouldn't do the trick, the sample rate is too low (16 ms/sample)
    – KoenR
    Jun 18, 2015 at 11:29
  • Still considerably faster than your 208ms
    – Majenko
    Jun 18, 2015 at 11:54
  • Think you misread :p, 0,208ms @ 12-bit resolution. But every bit of precisionmore it will take 4 times as long.
    – KoenR
    Jun 18, 2015 at 11:58
  • As opposed to 16ms at 22bit resolution...
    – Majenko
    Jun 18, 2015 at 11:59
3

This is in response to the question.
It is an answer to the extent that it says that

  • The current method may not work (several reasons given),

  • There may be better ways to do it, and

  • Is it necessary?

Addressing these points, or knowing that they have been addressed, is an essential part of arriving at a good solution .

If we knew the desired conversion time and actual desired resolution it would allow better answers.
If we knew what you were trying to do it might help immensely.
ie knowing what you are really trying to do may allow a quite different approach to be suggested or allow a fatal flaw to be identified.

Apart from the statistical sampling considerations that you are addressing, you cannot usually extend ADC bits indefinitely by oversampling with any great expectations of accuracy. Oversampling works on the basis of the variable + noise being linearly randomly distributed across the 'space' at least 1/2 a bit size either side of the true value. And it makes assumptions about ways in which ADC sample and hold and acquisition gating and more work.
As you try to squeeze more bits out of the ADC the assumptions become less likely to be consistently valid.

Also, implementation of the analog input circuitry initially becomes important and then immensely important as bits of ADC resolution increase (whether achieved by over sampling or other means).

12 bits = 0.0244% per step (as you know)
or 1.22 mV steps in a 5V reference system
or 0.81 mV/bit in a 3.3V reference system.
Getting your overall system working to that level of accuracy is possible but usually not achieved.
Any reference you are using will be natively much less accurate than that and those sort of accuracies will require calibration both initially and possibly ongoingly.
Ratiometric systems, where eg the excitation voltage of a bridge also serves as a reference, allow reference accuracy to notionally be perfect (as readings and excitation are the same and move together.
However, ensuring that the voltage at the controllers Aref pin wrt controller Agnd, and the bridge's excitation pin wrt the bridge's ground input are the same within usefully under 1.22 mV in a 5V 12 bit system (0.6 mV in a 13 bit system, and that the bridge and controller grounds are the same within say a few hundred uV, are an obvious necessity if the 13 bits of resolution are to be meaningful - but unlikely to be achieved without the most exquisite attention to both design & implementation. (Ask me how I know :-).)

Generally, it will be much easier to obtain and maintain ADC resolutions of as many bits as are needed by the use of purpose designed conversion ICs operating as close to the signal source as is reasonably possible. (Or using instrumentation amplifiers to acquire the signals and reliably "convey" them elsewhere.) Knowing desired conversion times and resolutions is a necessary first step.

BUT

Why?
Why is 12 or 13 bit accuracy and/or resolution needed?
What real world processes are being monitored that 0.012% perbit step sizes are not swallowed in the noise of reality?
Such requirements - and much more accurate again, certainly do exist.
But knowing what the actual application is may help with decisions of how to meet it.

1
  • Thank you for your detailed answer! questions answered in my original post
    – KoenR
    Jun 18, 2015 at 12:53
3

In my tests, the Arduino ADC starts to suffer from accuracy issues when you push it to 500kHz for oversampling, but 250kHz does not suffer from this problem. Also you need some kind of dither/noise, or the oversampling does not really work. I found that pulsing a digital pin with a resistor connected to ground gave me enough noise for the techinque:

https://edwardmallon.wordpress.com/2017/02/27/enhancing-arduinos-adc-resolution-by-dithering-oversampling/

1
  • I found that two factors really mattered when I am taking voltage measurements. First was a 100 uF cap across the analog pin and GND, and second was to make sure my voltage divider was set up to provide a sample voltage right in the middle of the ADC's range. Never did try to adjust frequency, but I did definitely notice that it wasn't accurate at all until it had taken a few readings (with short delays in between on the order of a few seconds) before starting the 1-minute-per-reading loop.
    – SDsolar
    Apr 10, 2017 at 5:08
0

you squeezing run time, I wonder, how much time you may save, if instead of looping to measure you do 16 times += and >>2 instead /4 an another optimization to make an own analog read function, it would be pretty simple based on original, so in additional you save time to call read function 16 times with all CPU overhead for each call.

lastly, in your own read function run the ADC in free run mode and accumulate a significant amount of data samples for oversampling.

1
  • Please improve your post by checking your grammar and semantics. I tried to edit it, but I don't get what you want to express.
    – Ariser
    Jun 10, 2016 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.