Author Topic: atmega 328p ADC reference voltage  (Read 3437 times)

0 Members and 1 Guest are viewing this topic.

Offline BlackICETopic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: us
atmega 328p ADC reference voltage
« on: July 04, 2023, 05:43:50 am »
The chip's ADC can use 3 sources as it's voltage reference.

internal 1.1 voltage
Vcc of about 5V
Aref user supplied voltage from GND to Vcc.

My use is single prototype that calibrating the voltage reference isn't a problem, but I only want to calibrating it once, not each time it is powered on. So the accuracy of the reference isn't so important, but the consistency and stability are. The internal 1.1v ref. would probably be OK but I would have to scale the inputs to not exceed the low ceiling, more parts and wiring. Using Aref with a voltage ref. would be best but also adds cost and wiring. So my question is if I use an external regulated 5V supply for Vcc, would it be as within +- 1% of the supply voltage stability? e.i. if the supply voltage is +-1% the worst case ADC conversion would be +-2%? How stable is internal Vcc given that the MCU has a lot of digital switching going on that the bypass caps have to deal with?

As for the Vcc supply how consistent are the typical USB supplies, or 3 terminal linear regulators? Do they drift a lot with temp or other reasons?


 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15469
  • Country: de
Re: atmega 328p ADC reference voltage
« Reply #1 on: July 04, 2023, 06:07:31 am »
The AVR chip has separate supplies for the main CPU part and the analog part (ADC, ref, port A and maybe the comparator). Unless there is significant current from port A there should be not much extra variations for the internal supply. One may want a low resistance filter (or none at all) in the analog supply.

USB supply is often not very stable (e.g. 4.5 to 5.2 V) and also quite noisy in the RF range.
Linear regulators can be quite stable and low noise, but it depends. If they get hot from high power there can be quite some thermal drift. E.g. 50 K temperature rise and some 100 ppm/K would result in a 0.5% voltage change.  With low current and a low drop (e.g. 5 V to 4 V) one should get less heating, if one does not use a very small one.

With only a single prototype unit the costs for a divider or exter reference should not be such an issue
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 7268
  • Country: ro
Re: atmega 328p ADC reference voltage
« Reply #2 on: July 04, 2023, 06:24:14 am »
the MCU has a lot of digital switching going on

One way to deal with this is to stop everything not needed before a conversion (put the MCU in low power mode, which stops internal clocks and switching).  For Arduino/ATmega328p there are code examples, search for low noise ADC conversion.
 
The following users thanked this post: BlackICE

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5699
  • Country: mn
Re: atmega 328p ADC reference voltage
« Reply #3 on: July 04, 2023, 07:02:20 am »
You may use as the ADC reference the AVcc (ie 5V), and you may measure the actual value of the AVcc with help of the internal 1.1V reference (search for the code snippet). Thus the ADC becomes "self calibrating".
Readers discretion is advised..
 
The following users thanked this post: BlackICE

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15469
  • Country: de
Re: atmega 328p ADC reference voltage
« Reply #4 on: July 04, 2023, 07:18:49 am »
the MCU has a lot of digital switching going on

One way to deal with this is to stop everything not needed before a conversion (put the MCU in low power mode, which stops internal clocks and switching).  For Arduino/ATmega328p there are code examples, search for low noise ADC conversion.
If the layout is OK there is no real problem for the µC to do other things also during the conversion. There is a special idle mode to reduce ADC noise, but from my experience it is usually not needed. The main point is avoiding to use port A during the conversion and not have a heavy load on port A, as this port is powered via AVCC. The pins adjecent to the Ref pin may also couple to the ADC.
 
The following users thanked this post: BlackICE

Offline BlackICETopic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: us
Re: atmega 328p ADC reference voltage
« Reply #5 on: July 04, 2023, 07:40:00 am »
Thanks to all for the information. I will avoid using port A. I need to the processor to be active for other stuff and plan to run the ADC as fast a possible using interrupt on conversion mode. I need to monitor an AC current sensor to estimate RMS and peak current by sampling the current many times during each cycle. This is used to monitor an AC induction motor so that I can maximize the motor's load but not to the point of motor damage.

That begs the question of how much overload current can an CSCR motor sustain without damage. The motor is used to turn an high pressure piston air pump. The pump has a variable pressure input stage, higher input pressure = higher motor loads. The motor turns a crankshaft via a worm gear transmission such that the loads are minimal for for much of the rotation. Significant loads only occur for about 40 degrees of rotation near TDC. The crank rotates at only once per 1.4 seconds. Thus peak loads only happen for 40/360*1.4 = 0.15 secs. The motor has a rated current limit of 9.5 amps with a service factor of only 1.15. However I have measured peak current waveforms in excess of 25 amps without any problems. Before any instrumentation I have stalled the motor at an unknown current, BAD! My though is to find the stall current and back off 25%+ to be safe or should I be more conservative? I'm guessing that the duration of the over current is such a small percentage that it wouldn't overheat the windings. Just preventing a rotor lock would be safe even though I'm driving much more than max. current. The startup current is much worst at over 48 amps.

I want accuracy in the measurement because I'm planning to use peak motor current as a proxy for pump pressure output. There should be a relationship between input pressure, peak motor current, and output pressure.


« Last Edit: July 04, 2023, 07:48:01 am by BlackICE »
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15469
  • Country: de
Re: atmega 328p ADC reference voltage
« Reply #6 on: July 04, 2023, 09:47:44 am »
The issue with the motor current is from overheating. The motors tend to be a relatively slow thermal system and can thus take quite some peak current for a short time. The relevant point is the RMS current, or more accurate the square of the current averaged for the last time constant (likely some 1 -5 minutes). This would be definitely shorter than the 1.4 seconds for a cycle.

1 phase induction motors with capacitor tend to not work very well with much high than there nominal load and the stall moment is somewhat limited. So one may not be able to go much (e.g. more than 150%) above the nominal current before stalling. The low duty cycle may already reflect this.
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 161
  • Country: gb
Re: atmega 328p ADC reference voltage
« Reply #7 on: July 04, 2023, 09:56:04 am »
A while back I needed an accurate Aref on a 328 Arduino so made a little daughter board using a simple boost converter to power a 5V LP2950 voltage regulator. These are not too expensive (sub 50p from Digikey) and accurate to less than 50mV with a reasonably low tempco. At low currents I've never found one quite that "bad", they're usually within 0.5%. Just don't buy them from China off ebay.

The boost-converter is junk-bin level components and powered from D13 set high, so it just plugs into three pins on an Arduino, if you're using the raw chip then you have more options. There are also 3V and 3.3V versions if the LP2950 (plus an adjustable 2951), and the same trick would work with other reference sources. It was about the cheapest solution I could come up with and works pretty well regardless of your main supply voltage.

 

Offline madires

  • Super Contributor
  • ***
  • Posts: 8476
  • Country: de
  • A qualified hobbyist ;)
Re: atmega 328p ADC reference voltage
« Reply #8 on: July 04, 2023, 10:21:01 am »
You may use as the ADC reference the AVcc (ie 5V), and you may measure the actual value of the AVcc with help of the internal 1.1V reference (search for the code snippet). Thus the ADC becomes "self calibrating".

The 1.1V internal bandgap reference can be anything between 1.0V and 1.2V. This is a tolerance of about 9%!
« Last Edit: July 04, 2023, 10:26:52 am by madires »
 

Offline ArdWar

  • Frequent Contributor
  • **
  • Posts: 721
  • Country: sc
Re: atmega 328p ADC reference voltage
« Reply #9 on: July 04, 2023, 10:43:31 am »
It's a bandgap, while you don't expect it to be accurate at least you'd expect it to be stable within a narrow temperature range. At least as good as many supply regulator in this regard. Should be usable after initial pre-calibration.

You may use as the ADC reference the AVcc (ie 5V), and you may measure the actual value of the AVcc with help of the internal 1.1V reference (search for the code snippet). Thus the ADC becomes "self calibrating".
Using this double conversion isn't "free" however. The rather small ratio between Vref and Vadc loses you a couple bits of ENOB (log2(5/1.1) ≈ 2.2 bits).

Using divider to scale the input to use the internal 1.1v reference is probably the cheapest and easiest option here if you really don't want to add supply regulator. Although the increased source impedance might not react well with sample and hold circuitry.
« Last Edit: July 04, 2023, 10:51:02 am by ArdWar »
 

Offline BlackICETopic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: us
Re: atmega 328p ADC reference voltage
« Reply #10 on: July 04, 2023, 10:49:46 am »
It's a bandgap, while you don't expect it to be accurate at least you'd expect it to be stable within a narrow temperature range. At least as good as many supply regulator in this regard. Should be usable after initial pre-calibration.

Using this double conversion isn't "free" however. The rather small ratio between Vref and Vadc loses you a couple bits of ENOB (log2(5/1.1) ≈ 2.2 bits).

I agree. That's why I reluctant to use it. This webpage suggest a LM4040AIZ4.1

 
https://skillbank.co.uk/arduino/measure.htm


Using the external voltage reference input pin AREF.


If you connect the external reference voltage to the AREF pin through a protection resistor of 4k7 or more, it allows you to switch between external and internal reference voltages.

Normally the resistor will alter the voltage that gets used as the reference because there is an internal resistor of ABOUT 32K on the AREF pin. The two act as a voltage divider, so, for example, 5V applied through the resistor will yield 5 * 32 / (32 + 4.7) = ~4.4V at the AREF pin.

This reference will be a FRACTION of the +5V supply, not a precise voltage reference.

However, by connecting a shunt mode voltage regulator as shown here you can set the reference voltage accurately WITHOUT the hazard of damaging the arduino.

The LM4040AIZ4.1 (5) is a micropower SHUNT voltage reference diode, and if we connect this to the "5V" supply through a resistor, so that a current of >60 uA and <15mA flows through the diode, it provides a voltage with an accuracy of 0.25%

How it works:


Lets look at the currents flowing;

R1 has (5V - 4.096 = 0.9V approx) across it so (if we choose R1=3k3 )
i1 = 0.9 / 3k3 mA or 270 microamps.

Rint has 4.096V across it so i3 = 4.1 / 32 = 128 microamps.

This leaves 270 - 128 = 142 microamps for the regulator.

You can use other regulator voltages by choosing a suitable value for R1.

 

Offline beanflying

  • Super Contributor
  • ***
  • Posts: 7386
  • Country: au
  • Toys so very many Toys.
Re: atmega 328p ADC reference voltage
« Reply #11 on: July 04, 2023, 11:03:54 am »
Going way back into 2018 you could actually buy a 4.096 plug in module for the Arduino or similar. I had a search and the link is long dead but it worked fine and I still use it on a breadboard from time to time.

Based on a REF431 https://www.ti.com/lit/ds/symlink/tl431.pdf?ts=1688431132637&ref_url=https%253A%252F%252Fwww.google.com%252F

Sorry for the junk photo but you can get the idea it is low parts count.

« Last Edit: July 04, 2023, 11:05:59 am by beanflying »
Coffee, Food, R/C and electronics nerd in no particular order. Also CNC wannabe, 3D printer and Laser Cutter Junkie and just don't mention my TEA addiction....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf