2
\$\begingroup\$

I've followed advice on the web on how to use "bandgap" voltage reference to measure supply voltage, however, the measurements are not as accurate as the ADC can be on an Arduino Mega.

On the one hand, I've measured the 1.1V ref to actually be 1.087V using a DMM to measure the voltage across a capacitor from AREF to GND with the appropriate code.

On the other hand, measuring the BG internally with the ADC using the attached code returns an ADC average reading of 226.5 which is 1.107V with a 5V supply (measured using a DMM from the 5V pin). This is a 20mV error. I've being getting about 5mV accuracy when using the ADC to measure an external voltage source.

The Arduino Mega is powered via USB.

  • An external supply of 1.087V was simultaneously (alternately) measured with the analog pin yielded a different reading. What is the difference between the two passes?

    #define N 128
    #define ND 128.0D
    
    int analogReadBG(){
      uint8_t low, high;
      ADMUX = 0;
      bitClear(ADCSRB,MUX5); // Set ADC input as BG (1.1V)
      bitSet(ADMUX,MUX4);
      bitSet(ADMUX,MUX3);        
      bitSet(ADMUX,MUX2);
      bitSet(ADMUX,MUX1);        
      bitSet(ADMUX,REFS0);  // Set 5V as ADC reference voltage
    
      for (int i=0;i<7;i++){ // Perform several converstions for reading to settle
        bitSet(ADCSRA, ADSC);
        while (bit_is_set(ADCSRA, ADSC));
      }
      low  = ADCL;
      high = ADCH;
      return (high << 8) | low;
    }
    
    void setup() {
      Serial.begin(115200);
    }
    long movingSum;
    double movingAverage;
    void loop() {  
      movingSum = 0;
      for (int i=0;i<N;i++){
        movingSum += analogReadBG();
      }
      movingAverage = movingSum/ND;
      Serial.println(movingAverage);
      delay(1000);
    }
    
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Have you checked the 5 volt supply? It is not necessarily perfectly 5 volts which would skew your readings. \$\endgroup\$
    – TylerH
    Apr 4, 2015 at 16:21
  • \$\begingroup\$ As I've mentioned, I measured the the supply voltage using a multimeter on the 5v pin. This value gave accurate readings of external supplies through the analog pin. \$\endgroup\$
    – sas
    Apr 4, 2015 at 22:15
  • 1
    \$\begingroup\$ You appear to be regarding your DMM's readings as gospel truth. Do you have a good reason for this like recent calibration certificates, etc ... ? Even the best brand name units will drift over time and end up little better than the bargain-box variety without calibration. \$\endgroup\$
    – brhans
    Apr 6, 2015 at 13:21
  • \$\begingroup\$ If there was indeed a drift in the DMM, the ADC reading of external voltage supplies wouldn't be consistent. \$\endgroup\$
    – sas
    Apr 6, 2015 at 17:56
  • 1
    \$\begingroup\$ Although you have checked the external supply, there is an internal reference (2.56V). You might want to rerun the experiment using this as the span reference voltage to eliminate power source issues (which quite often exist with ADCs). The datasheet also recommends throwing away the first conversion after setting the reference to be used. Just a couple of thoughts. \$\endgroup\$ Aug 3, 2015 at 11:05

1 Answer 1

2
\$\begingroup\$

There are two big sources of error you do not appear to have considered- the reference voltage (your USB supply voltage), which could easily be low by 2%, and the ADC error, which is of the order of 2-4LSBs. Since you're only using the lower 20% of the ADC range, that represents a relatively large percentage error of 1-2% of reading. Averaging many readings does not reduce either of those errors.

Also your number of 266.5 does not make sense with a 5.000V reference. 226.7 would be expected from your calculation and 222.6 as the nominal exact value with a 5.000V reference and a 1.087V input.

\$\endgroup\$
2
  • \$\begingroup\$ First of all, as I've mentioned, the supply voltage was measured with a multimeter on the 5V pin to be exactly 5V (up to the accuracy of the multimeter). This measurement gave good results when measuring other external voltage sources with the ADC. Secondly, the datasheet only specifies an error of +-0.5LSB, how do you come up with 2-4LSB? Averaging might help in certain cases - depending on the characteristics of the added noise to the input signal. \$\endgroup\$
    – sas
    Apr 4, 2015 at 16:52
  • 4
    \$\begingroup\$ @sas - Spehro is referring to the AT2560 data sheet atmel.com/images/doc2549.pdf Note that section 26.1 gives the absolute accuracy of the ADC as 2-4 lsbs. Important lesson here - resolution is not accuracy. \$\endgroup\$ Apr 4, 2015 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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