[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] measuring uC supply voltage
From: |
Ned Konz |
Subject: |
Re: [avr-gcc-list] measuring uC supply voltage |
Date: |
Fri, 29 Oct 2004 08:43:02 -0700 |
User-agent: |
KMail/1.7 |
On Friday 22 October 2004 7:03 pm, JAMIE MORKEN wrote:
> I am trying to figure out the best way to measure the 5V supply voltage for
> an atmega128. I am using the 5V supply as the ADC reference voltage. The
> problem I am seeing is when the 5V supply droops, the reference voltage
> will also droop. For other sensors I need to use the 5V reference voltage.
> Any ideas on how to solve this? Is it possible to switch to the internal
> 2.5V reference while the 5V external reference is still hooked up? Thanks,
Many chips have a 1.22V "bandgap reference" (VBG) attached to the input mux
that can be measured without changing your Vref supply. I don't have an
Atmega128 manual here, but the Atmega16 has this. On that chip, if you set
MUX4..0 to 11110 you read the 1.22V bandgap reference.
This internal bandgap reference is pretty stable over time and temperature
(like within 1% over a practical range), though its absolute accuracy is not
too great. If absolute voltage accuracy is not important (which it sounds
like it is not), or if you're willing to calibrate the initial offset, then
you should look at the stability of the internal bandgap reference and see if
it's OK for you.
In the Atmega16 data sheet, this is spec'd as being 1.15-1.35V, with a nominal
1.23V. They show a graph that shows the voltage varying from 1.235 to 1.242V
over the -40 to 85 degree C temp range (at 5V) and from 1.238 to 1.230 V over
the 5V to 2.7V VCC range.
So over 2.7V to 5V, and over -40 to 85V, the total variation is only
(1.242-1.230)/1.23, or about 1%. If you're operating over a more reduced
temperature or voltage range, it's even tighter than that.
The 2.56V reference that you can use for the VREF is derived from this 1.22V
bandgap reference, so any graphs you see that show the stability of one will
apply to the other.
If VREF is 5V, then you will be reading about 1/4 full-scale (0x100 or 0x40,
depending on whether you're reading 10 bits or 8 bits) when you read this
reference.
So if you keep your 5V Vref, and then make an 3R/R resistive voltage divider
(you can go pretty high with these resistor values; 3.3Meg/1Meg would be
fine), you can read the voltage at the resistor junction with one of your A/D
inputs. Using a 3.3Meg/1Meg, the voltage at 5V VREF would be 1.16V
(3.3Meg/1.2Meg gives 1.33V)
By taking the ratio of that divider reading to the reading of the internal
bandgap reference, you can get a multiplier to apply to your potentiometer
readings:
correctedReading = rawReading * bandgapReading / vDividerReading
So as the supply voltage changes, the vDividerReading changes but the
bandgapReading doesn't and you get a correction factor.
The bandgap and vDivider readings don't have to be done very often, of course,
as the ratio will change very slowly as the battery droops.
--
Ned Konz
http://bike-nomad.com