ADC gives wrong results

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First time programming an Atxmega A. Here's my code:

 

ADCA.CTRLA = 1; //Start ADC

ADCA.PRESCALER = 0b111; // Prescaler=512

ADCA.REFCTRL = 0b11; //Bandgap as reference

_delay_ms(1);

ADCA.CH0.MUXCTRL = 0b00110000; //ADC6 as input

ADCA.CH0.INTCTRL = 0b10; //Medium level interrupt enable

ADCA.CH0.CTRL = 0b10000001; //Single ended input, start conversion

 

ISR(ADCA_CH0_vect) {

Send_Intln(ADCA.CH0RES);

ADCA.CH0.CTRL = 0b10000001;

}

The ADC6 input is connected to a 1k+180Ohm resistor divider from the 3.3V supply, it reads exactly 0.5V on my DMM. The atxmega ADC gives me around 2230 which translates to 1/4096*2230=544mV. When reading the internal Vcc/10 input, it gives me 3.8V even though the supply is 3.3V. Changing the voltage reference gives different results, but the scale of error seems to remain the same. I've kind of run out of ideas on what's causing this :(

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which actual model of Xmega is this? The Atxmega128a1 for example rather famously has an ADC that is totally FUBAR (which is why it was phased out and replaced by Atxmega128a1u)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sound like it is working fine...You say you gave 0.5V & it is indeed reading 0.544

 

That seems within the +/-10% adc tolerance , plus +/- your resistor divider tolerance. 

 

Why do you question it?  How good is your DMM?

 

If you gnd the pin , do you read zero?

If using Vcc ref, do you red 1023 when tied high?

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In that mode the measurement result is offset by about 200.
Measure the GND level and correct the result.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adjusting for about 160 offset gave me proper results. Why does it have an offset though? :\

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

forgot about the Xmega weirdness, compared to the "classic" AVR ADC....here is some good info with a lot of explanations:

 

http://embedded-lab.com/blog/xmega-adc/

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The usual advise is:

Remove all calculations and work with the raw ADC values untill you are sure the ADC works properly.

 

Just adding a potentiometer and try different values. Does it seem to be linear with voltage?

Are there offsets?

 

A nice way to verify the working of your ADC is with a capacitor and a current source.

You should get a nice straight line out of your ADC values. (if sampled at regular intervals).

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Plecto wrote:
Why does it have an offset though? :\

I'm no XMega man, but a look in the sheet gives this:

Since the ADC is differential, the input range is VREF to zero for the positive single-ended input. The offset enables the ADC to measure zero crossing in unsigned mode, and allows for calibration of any positive offset when the internal ground in the device is higher than the external ground. 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since the ADC is differential, the input range is VREF to zero for the positive single-ended input. The offset enables the ADC to measure zero crossing in unsigned mode, and allows for calibration of any positive offset when the internal ground in the device is higher than the external ground. 

Similar to single supply opamps...if you REALLY want a zero in/out (0.0000...), you need dual +/- supplies (or "split" a single), pure single will only get you 99.43% of the way there since an output can't go all the way to gnd.  Here, they fake a negative supply voltage with the offset.

When in the dark remember-the future looks brighter than ever.

Last Edited: Sat. Jan 27, 2018 - 11:44 PM