Xmega ADC voltage range

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

I've been playing with the ATXmega32E5 and now I'm testing its ADC, looking on this forum I've found that the max voltage for a correct conversion is Vcc - 0.6V even when using the AREF (PD0 for exeample) connected to Vcc. It also matches with the practical results that I have found. The problem is that I don't find this information in the manual nor in the datasheet. Can someone show me where I can find it, or if I'm making something wrong when I set the parameters for a convertion?

 

Regards. 

Regards!
FS.

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

http://www.atmel.com/Images/Atme...

 

 

On page 76:

 

AVCC Analog supply voltage                VCC- 0.3 VCC+ 0.3V

VREF Reference voltage                       AVCC- 0.6

 

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

Greg left out the final piece of information, Vin.

Page 77, the continuation of the Table 36.6 ADC Characteristics, states that Vin, (Input Range): Min = 0, Max = Vref, units are volts.

 

Granted, it takes a little looking about to find it!

 

Note also that the Conversion Range for both single ended and differential input mode are listed in the same table, and worth taking a look at.

 

JC

Last Edited: Tue. Jan 6, 2015 - 02:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you guys.

Some times I think that the old stile of datasheets that Atmel used to have (i.e. for the Atmega chips) were clearer. Divide the information in two files is not good!

 

I appreciated your help.

Regards, Felipe.

Regards!
FS.

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

Hello,

 Guys I am using atxmegaE5 controller an am  trying to read adc values by varying a potentiometer of 10k.The issue that am facing is I do not get the maximum range value of 4096,instead it scales down to half of it,i.e 2023,and also it does not give me zero value when potentiometer is at its maximum value,instead her too it gives me 2023 value,while when set to minimum resistance too it gives me values around 2023.Can anyone help me solve this problem..?

 

kevin

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

Are you doing a signed or unsigned conversion? If it's signed you'll only see +2047/-2048. If you're not handling the sign correctly you may see the result you're getting.

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

no I have configured it for unsigned operation.I have attached my code.

Attachment(s): 

kevin

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

Are you able to verify the register settings in the hardware, using a debug tool? Is everything as it should be? is the voltage swing at the device 0-3V3 when you turn the pot?

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

yup,I am using an external reference voltage of 1.25V on port D,and yes the voltage swing is from 0-1.25V.

kevin

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

Have you checked the control register is set correctly in accordance with

25.15 Register Description - ADC Channel

25.15.1 CTRL – Control Register

 

I also note that you read the ADC result in 2 different places. What is the result in the ISR rather than main()?

 

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

There is not much of difference in the values used in these two places.I just used it to observe the rate at which value in result register changes.

 I just found out what was going wrong in my code.I had configured the CTRL B register in freerun mode.The moment I set it to no freerun mode,my ADC began working.

kevin

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

hi to all

i want measure the negative voltage analog i.c( range of -5v to +5v) with atmega or xmega?

PLEASE HELP MY.

thanks to all.

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

A simple and easy to understand way to go about this is to set up a two resistor voltage divider, with the upper end connected to some (low impedance) positive reference voltage,  the bottom end connected to the voltage you want to measure (which also should be from a low impedance source), and the middle going to the A/D converter.  If you don't have low impedance sources, you can feed the voltages through op amps set up as voltage followers first. Select the resistors (Ohm's law etc.) to give you the range you want.

 

If you complain (justifiably) that when the input voltage is at the top end of the range, the output is too high for the A/D input, you can add a resistor from the middle of the voltage divider to ground.

 

Or you can select the reference voltage so that it's enough lower than the maximum A/D input voltage that when the voltage to be measured is at +5, the A/D input voltage is at maximum.

 

Or maybe some variation on this, with values changed to suit your circuit:

 

sch

This avoids having to use a negative supply for the op amp, but requires one whose output goes down to the negative rail.

 

 

These are just rough ideas, you'll need to decide on the details for yourself.

 

 

Last Edited: Sun. Apr 26, 2015 - 05:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

very thanks from solution.

but is there a way to directly connect the analog input to the A/D Xmega?

 

because, I've seen in datasheet of xmega for ADC with signed mode and single ended and the digital values is between -2045---+2045.

thus how in xmega, i can obtain minus digital( -2045---- 0) while you say cannot connect the negative voltage to xmega(ADC).

I'm confused.

please help me.        

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

The numeric values are have initially nothing to do with the polarity of your input voltage.

himahdiyou wrote:
but is there a way to directly connect the analog input to the A/D Xmega?

No, you cannot connect a +-5V signal directly to an adc input pin.

 

But you can use 3 resistors only, one from your +-5 Volt signal into the adc pin, one from the adc pin to ground and one from the adc pin to VCC (3.3V).   The values you have to calculate yourself.    Start with choosing the first resistor to 1..10k maybe and calulate the other two so that you get 0V at the adc pin when your signal has -5V and that you get Vref at the adc pin when your input signal is at +5V.   Maybe leave a bit of margin for overshoot and adc offset.

 

edit: added offset.

 

Last Edited: Sun. Apr 26, 2015 - 01:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The maximum input voltage range is (as said above) 0..2.7V.    But when you use differential mode you can get set the ADC to signed output and get negative numeric values.    So if VIN1 == 0.8V and VIN2 == 1.5V and you convert differential VIN1 - VIN2 = -0.7V you would get an adc value of -986 (0.7 * 4096 / 2.7V - 2048).   See also chapter 28.6 "Conversion result" in the Xmega AU manual.

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

Yes, as Hugo noted, negative values coming out of the A/D converter do not mean you can feed a negative voltage to it.  It's possible to use the A/D in differential mode, in which the output is the difference of two (positive) input voltages.  If voltage A is bigger than voltage B, you get a positive number; if the reverse is true, the number is negative.  But that information doesn't apply to your situation.

 

The three resistor method mentioned above is probably what you need.

 

If you can use 10 bits instead of 12 bits, I'd recommend not using the xmega unless you need its other capabilities.  The datasheet description of the A/D converter for the xmega is complex and confusing, and seems to generate a lot of questions.
 

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

very thanks from my friend for best solution .

 

whether is there another way for input signal analog to xmega  (note:  instead of resistor method)

 

because for i, Accuracy is important ( resolution   0.0001V ) 

with method resistor, the ADC is not accuracy. ( Due to resistance in path signal analog input)

 

please help me.

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

That resolution - .0001 V out of a 10 V range - implies a 16 or 17 bit A/D.  The internal xmega A/D is only 12 bits, and I have a recollection (from using it a year or so ago) that under some practical circumstances, that 11 bits might be a more appropriate description.  The  A/Ds on the other AVRs are only 10 bits.

 

If you don't think the resistor method is accurate, or accurate enough for your needs, you should probably explain exactly why.

 

 

 

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

tominsf wrote:
...I have a recollection (from using it a year or so ago) that under some practical circumstances, that 11 bits might be a more appropriate description.

Am I right in the assumption that that was only achieved with (per piece) calibration of offset and range?

Last Edited: Sun. Apr 26, 2015 - 08:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In fact I was just reading relative rotation of a pot, and I purposefully put dead zones at each end of the pot range, because I wasn't interested in an absolute value.  Linearity was more important.

 

My remark about 11 bits is just a vague recollection of something I can't quite pin down without going back to the spec sheet and reading it.  Is it that you only get 12 bits in differential mode? I just don't remember.

 

 

Last Edited: Sun. Apr 26, 2015 - 08:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I'd better retract what I said about 11 bits.  On reading the datasheet, there doesn't seem to be the problem I remembered.  Maybe it was some special circumstance in my circuit that kept me from using the full range.

 

Hugo, it sounds like you've had a bad experience with xmega A/D accuracy.

 

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

No, I would not say bad experience.   

 

Most ADCs with n marketing bits resolution have only n-1..n-3 bits usable resolution (and / or accuracy), so that part I am not worried about.   And the data sheet mentions the calibration row value that you have to copy to get the linearity; again, no problem here.   But it then says that you have to do offset and range calibration yourself (please correct me if I'm wrong).    This is not a big deal for a board on the bench but in a production environment this is a significant cost factor.

 

My experience with the Xmega series is very positive, from a hardware and particularly from a software perspective due to the structured peripheral register addresses.    Main reason we changed at the time was lack of availability of CPLDs and FPGAs for 5V supply but I would never go back to Mega devices.

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

Yes, I like the atxmega.  It seems like it's likely to be more cost-effective than mega parts while having broadened capabilities.  For instance, in the case of the cheapest devices with on-board USB capability, the xmega part is 70% of the cost of the mega part (in unit quantities).

 

What I don't like is the documentation.  The datasheets are missing vital information that you have to guess at or research elsewhere.  I think the tinys and megas have better datasheets.

Last Edited: Mon. Apr 27, 2015 - 09:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The datasheets are missing vital information

 

 

I assume you are aware that for the Xmegas one has to use TWO data sheets. 

One is for the family of chips, the other is for the specific chip.

 

This has come up in several Threads.

I wish is was all in one data sheet, others like the current setup.

 

Tough to please all of the people all of the time...

 

JC 

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

Oh, yes.  But taken together, I don't see them as telling the full story, as I've mentioned in this post:

 

https://www.avrfreaks.net/forum/xmega-usb-bulk-transfer-without-asf-or-lufa

 

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

It is also worth noting that Atmel has updated many of the Xmega data sheets.

 

Make sure you are using a recent one!

 

The earlier data sheets were released with many parameters left blank, especially when the initial A series first rolled out.

 

JC

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

I promise!  The ones in question (the xmega C Manual and the 16c4/32c4 Complete)  I downloaded within the past few weeks, and haven't been updated since 12/2014.

 

The information missing involved handshaking (for lack of a better word) between firmware and hardware during USB enumeration and USB transfers.  The information in the AT32UC3B datasheet is much more complete on this subject, if complex and confusing.  I have the impression that there's also fairly complete info in the atmega8u2 series datasheet on USB as well.

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

That is the problem.   Due to lack of skill in the programmers they throw some sample code at you and say: use this.    And then they think they don't have to write correct and complete documentation any more.    I wonder what type of information they gave the programmers that wrote the sample code....

Last Edited: Tue. Apr 28, 2015 - 07:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I, too, have been working with the ATxmega ADC in a 64A3U device.  I have an external 2.500V reference, and am using the single-ended conversion mode.  With 0V on the selected ADC input, the conversion result is something around 190 LSBs.  I know that this is the expected offset value mentioned in the manual.

 

Please check my understanding . . . it's a 12-bit ADC, so it resolves one part in 4096.  Since the reference voltage is 2.500V, one LSB corresponds to 2.500V/4096 = 610.352uV.  Since the 0V conversion value is ~190, and the maximum conversion value is 4095, that gives a conversion value range of 3905 (after subtracting the offset).  That appears to say that the maximum input voltage is 3905 x 610.352uV/LSB =2.3834V.

 

In other words,

 

ADC in (V)        ADC conv (LSBs)

0                     190

1.25                2238

2.3834            4095

 

Is this correct, or did I miss something?  I'm not used to this weird 190 LSB offset . . . it seems like more of a bug than a feature . . .

 

Thanks.

 

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

is this correct, or did I miss something?

Almost but not necessarily so , the "feature" is also available in the UC3 from what I understand.

 

So you need to perform lots of magic in order to read an ADC usually involving another WASTED ADC pin for reference.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I did connect one of the ADC inputs directly to GND so I could measure this "offset" directly . . . At least I wasn't crunched for needing more I/Os.

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

If you search on this site you will find MANY people bellyaching about the Xmega' ADC (me included).

 

It's a supposed "feature" to allow easier zero crossing detection, or at least that's what I remember being told. Pity it stuffs up the majority of people not needing that feature. angry

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
It's a supposed "feature" to allow easier zero crossing detection

Feature, me arse...   With two resistors I can add any offset I want with any accuracy I can afford.   Having to do offset (and possibly gain) calibration for each individual device is costly.   Of course, Atmel is saving the time (and money) on their IC tester.  Something to remember when selecting ICs...

Last Edited: Thu. Apr 30, 2015 - 07:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is an internal GND reference you can use to either measure the offset or make a double ended conversion with.

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

giving you full analogue range 0..Vref corresponding to 0..4095?

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

js wrote:

If you search on this site you will find MANY people bellyaching about the Xmega' ADC (me included).

 

It's a supposed "feature" to allow easier zero crossing detection, or at least that's what I remember being told. Pity it stuffs up the majority of people not needing that feature. angry

 

I agree. This "feature" sounds suspiciously like a bug to me.

 

But then, I once fixed a bug that had been touted as a feature for years. The outcry was deafening and the peasants stormed the gate.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

hugo_habicht wrote:

giving you full analogue range 0..Vref corresponding to 0..4095?

 

If you are using the single-ended ADC configuration, your data range will be 190 (approx) to 4095.

 

ADC in          ADC conv

0.00V          190 LSBs (approx)

Vref*0.953  4095 LSBs

 

I am using a 2.500V external reference on REFA.  For me, the ADC looks like this:

 

ADC in          ADC conv

0.0000V          190 LSBs (approx)

2.3834V          4095 LSBs

 

Thus, the actual data range is 0-3905 LSBs (subtracting the ~190 LSB offset.)  The LSB value is still 2.500V / 4096 = 610/35uV.

 

Good luck with the xmega ADC - you will require it.

 

Altazi

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

ok, but if you use the internal ground in diff configuration as mojo-chan suggested would you get the full range?

 

I don't need luck; what we did with the Xmegas ADC so far worked as described in the data sheet (accuracy or low offset was never required so far).

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

hugo_habicht wrote:

ok, but if you use the internal ground in diff configuration as mojo-chan suggested would you get the full range?

 

 

Stand by for more experimentation . . .

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

OK, here are some results.  Please correct me if I have made an error somewhere . . .

 

ADCA configured for differential input, signed mode (required for diff.), 2.500V external reference.  MUXPOS = ADC input pin, MUXNEG = int. GND.

 

Vin       Conv

2.49    2047
1.25    1015
0.01    0
0.00    65530

 

The range is basically 0-2047 when the POS input is greater than the NEG input.  If I had configured the differential inputs to be two ADC input channels, I suspect you get the negative results when the voltage on NEG is greater than that on POS.  Of course, you cannot hook up a voltage lower than GND to the ADC inputs . . .

 

So, it appears that there is no way to get the full 0-4095 conversion range out of the ADC.  The single-ended mode gives about 3905 LSBs of range, and that appears to the the best I can get.

 

Unless I am missing something . . .

 

 

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

Thank you for the test results.    The other 2048 are reserved for the negative diff which we obviously don't want to use.    So basically an 11-bit converter then.   You can get full range in single ended if you have a bit of negative supply voltage in your system.

 

I particularly like the 65530 (negative result); that's really what I would expect back from an ADC; certainly easy to handle for beginers that get an IC with slightly positive or zero offset for testing their software and then production gets a batch with negative offset.

 

Performance on the software side obviously wasn't a design criteria and if John is right and that "feature" was put in for zero crossing detection I'd strongly suggest that Atmel replaces some personnel that make those decision in their IC design (has hopefully happened already).

 

Enough complaining now: still useable and I would never go back from the Xmega to a Mega AVR.   Event system is great, the hardware drivers are reduded to half nothing thanks to a bit of organisation in the peripheral registers, one crystal covers all frequencies on our boards, a.s.o. a.s.o.

Last Edited: Fri. May 8, 2015 - 04:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm looking to use the ADC on an 8E5 to grab 8-bit values from a few user controls (rotary pots).

 

Reading the data sheet I noticed that the Vin (Conversion Range) is specified as 0.95*Vref max.  Does this mean if you have a 2.5V external Vref the actual measurement max is only 2.375V ?

 

This makes no sense to me.  That would mean if I feed the user controls from the same external voltage reference, I'll run out of range before the control reaches 100%.

 

Is there something I'm missing here?  All I need is a 0..255 return value for each control.

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

All I need is a 0..255 return value for each control.

Then you are cursed unless you do some magic. In single ended mode you get a theoretical 205 offset at 0V in. With calibration, offset adjustment fed into the OFFSETCORR register (12 bit value) and calculating the gain error and feeding it into the GAINCORR register (12 bit value) you can get incredibly accurate results.

 

The offset adjustment value is easy if you waste an ADC input (like I and other have done) and connect it to GND so that you can read the REAL offset (something other then the theoretical 205), then use it to calculate the gain error by using another input to measure the maximum span. (formula in datasheet).

 

All of the above applies to the 11.4 bit ADC (95% of VREF).

 

Table 24-6 shows you how to get 8 bits values instead of 12 bits (or 11.4 actually). Never used it myself, most of the reason I used the Xmega was the 12 bit ADC.

 

By the way any input from others on easily calculating gain error welcomed here blush I'm still struggling with that at the moment.
 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Sep 1, 2015 - 01:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ADC implementation in the XMEGA certainly seems err.... unusual.

 

Maybe I'll look at another type of chip with a few analog channels and a few PWM outputs.  Can be 3.3V or 5V in SOIC or TQFP32.

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

Looks like the ATTINY441-SSU will do everything I need and way simpler to use.  :)

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

Hi David,

 

For what you want to do (read an 8 bit value from pots) I'm pretty sure you can just use signed single ended mode on the ADC. I found some code I did testing this on the xplain board. It was a few years ago but I'm pretty sure it worked. I just had a pot wired between the external reference and ground going to one of the ADC inputs, and displayed the result on the 8 LED's. I'll see if I can find the pot with connector and try it again.

 

When you use signed single ended mode the - input of the ADC is connected to ground. This guy has some more info...

http://embedded-lab.com/blog/?p=...

 

Stew.

 

 

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

First off, pots aren't very precise themselves.

 

So put your pot between ground and vref and the wiper to the pin. Turn it all the way down and record the "low." Then turn it all the way up and record the "high."

 

Now, in operation, to see where the pot is, measure it, then subtract the low. Then multiply by the 256 you want for your max and divide by the difference between high and low.

 

In a recent project, I had 2 pots to adjust the "speed" of the thing somewhere between 1 and 10 seconds and nobody cared much what the speed really was. So I just read the pot and set the timer. Even with that sloppy design, it is more than accurate enough for the task. Oh, yes, I counted a second as 2048 ticks at 2MHz. Who needs an exact second when the adjustment is a knob and the desired speed is "that looks about right."

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

One of the BIG difference with the E5 family's ADC seems to be the addition of the "Offset and gain correction" registers and the CORREN enable bit to use hardware offset and gain correction. I don't seem to find the same in any other Xmega family.

 

So all code examples seem to use the old fashioned way of saving the offset value into a variable and then subtracting it from the results, no code seem to address the gain correction issue, maybe it's too new in the E5 series and nobody knows how to use it? It this the reason why a get a deafening silence to my pleas for help with this feature?  smiley

 

The hardware of the E5 can do the offset and gain correction when enabled and properly set up, no need for any code to adjust things.

 

My plan is to have automatic self calibration, the 1st bit is easy, read the condemned ADC pin connected to ground and save the result in the  OFFSETCORR register.

The 2nd not so easy, so I simply put the 0x0800 (unity gain value) in the GAINCORR register and then adjust that value up or down manually until it's "perfect".

 

The only way I can think of reading the ADC's maximum is to read the pin with AREF and then do the calculation below and save the results into the GAINCORR register, but I'm not too sure it's the correct way of doing this.

 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly