Here's (my interpretation of) the real poop on the ADC range.
The short answer is that the Vref is VCC and that's the max you
can convert...Also, this is good news if you are running on
batteries with passive sensors because their output will droop
with the battery voltage, in sync with the conversion reference.
From the ATMEGA 128 manual --
The ADC converts an analog input voltage to a 10-bit digital value through
successive
approximation. The minimum value represents GND and the maximum value represents
the voltage on the AREF pin minus 1 LSB. Optionally, AVCC or an internal 2.56V
reference
voltage may be connected to the AREF pin by writing to the REFSn bits in the
ADMUX Register. The internal voltage reference may thus be decoupled by an
external
capacitor at the AREF pin to improve noise immunity.
>
> ...
>
The reference voltage for the ADC (VREF) indicates the conversion range for the
ADC.
Single ended channels that exceed VREF will result in codes close to 0x3FF.
VREF can be
selected as either AVCC, internal 2.56V reference, or external AREF pin.
AVCC is connected to the ADC through a passive switch. The internal 2.56V
reference
is generated from the internal bandgap reference (VBG) through an internal
amplifier. In
either case, the external AREF pin is directly connected to the ADC, and the
reference
voltage can be made more immune to noise by connecting a capacitor between the
AREF pin and ground. VREF can also be measured at the AREF pin with a high
impedant
voltmeter. Note that VREF is a high impedant source, and only a capacitive load
should
be connected in a system.
If the user has a fixed voltage source connected to the AREF pin, the user may
not use
the other reference voltage options in the application, as they will be shorted
to the
external voltage. If no external voltage is applied to the AREF pin, the user
may switch
between AVCC and 2.56 V as reference selection.
So the reference choices are either AVCC (the separate power pin for the
ADCs, so you can decouple it from the digital noise better), the
internal 2.56v reference, or an external voltage applied to the AREF pin.
In any case that voltage (minus 1 bit) is the maximum you can convert.
According to the schematic AVCC is connected via a filter to VCC so it's
basically the battery or power-supply voltage. Also on the schematic,
AREF is connected to VSNSR which is connected to VCC by a 0 ohm resistor...
Given that the power switch is bypassed by a 0 ohm resistor as well,
this may be a misnomer for an infinite resistor, meaning that it is not
connected to anything but that it _could_ be if one found the right pads
on the board. However this is belied by the software setting described
below, and my experience that the VSNSR voltage is close to VCC.
So then it boils down to how the REFS register bits are set when doing
a conversion. Now we gotta look at the code...which hardly ever makes any
sense to me...
It looks like the REFS bits are set to 00 in the HPLADCM.nc ADC.init() at
outp(0, ADMUX), which is "use the external voltage at the AREF pin".
I can't find any other reference to REFS anywhere so I'm going to assume
that this means that the ADC Vref is actually VSNSR which is actually VCC,
the confusion over the hermeneutics of a 0 ohm resistor not-with-standing.
The other confusion is that there is a separate CalADC interface which
uses an internal 1.23v calibration reference to adjust ADC readings.
This is what you saw in ADCREFM.nc. I think this only comes into play
if you wire to CalADC instead of ADC. But YMMV.
Anyway...the comments that set this ship sailing: "(2^6-1) * Vref"
and "Vref is 1.23 Volts", seem to be totally wrong at worst and
misleading at best.
phwew...
MS
Michael Schippling wrote:
huh...I'd better go look at the code and schematic for the acutal Vref..
I should already know this, but I've not been concerned with accuracy
in my conversions...
But the interpretation of the formula is incorrect. The formula is the
same as the one I sent. Vport is the acutal analog voltage at the
converter input (not the binary output (ADC) which is written as (2^6-1)).
Effectively it's the ratio of the input to Vref times the max for the
number of bits of conversion. Mica's have 10bit converters so that's 1024.
I don't know where the 2^6 comes from...maybe an older device with 6 bit
converters, or a typo.
In any case the maximum voltage on the pin is speced at something around
Vcc + 1 or there-abouts. I stand by the assertion that the max input
reading
is _close_ to the Vref because that's how successive approximation
converters
work...I will spend a bit of time looking into what Vref actually is...
MS
TEAM X wrote:
Thanks for the help, I will take a look at your code. But I just want
to put this out there.
According to the comments in tos/platform/mica2/ADCREFM.nc :
/* OS component abstraction of the analog to digital converter using a
* fixed reference input. I assumes the presence of a
TOS_ADC_BANDGAP_PORT
* to provide that referenced reading. This module was designed to
* accomodate platforms that use varying/unstable ADC references. It
also
* works around limitations where the measured variable cannot be
larger than
* the actual ADC reference
*
* The conversion result is given by the equation:
*
* ADC = (Vport * 1024) / Vref
*
* Where Vport can be between zero and (2^6-1)*Vref (I.E. Vport CAN
be larger
* than Vref)
*
* Note: On the ATmega128, Vref (using this module) is 1.23 Volts
*/
(2^6-1)=63
63*1.23 = 77.49
This is obviously incorrect, so I would to know what the real range of
inputs on the ADC is if anyone knows.
Thanks again,
Joe
On 2/3/06, * Michael Schippling* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
There are some examples of using the ADC component directly in my
huge
bolus of code at: http://www.etantdonnes.com/Motes/robocode.tar.gz
Most likely you have not made the ADC and input so you are converting
the equivalent of a logic 1...
The only special sensorboard stuff is that they switch on internal
sensors (photo,temp) using digital outputs from some specific pins
and then make sure to switch the ADC to the right channel. The code
should work pretty well without the SB attached. You should be
able to
connect your input to ADC1 and use the Photo component to get
started.
I'm a little confused by your math...basically Vref is the Max
voltage
and 0 is the Min. I think it should be ADC = (Vin / Vref) * 1024
where 1024 is the maximum reading from a 10 bit converter. Also I
believe
Vref is the supply voltage or very near, so 3 volts.
MS
TEAM X wrote:
> Hi,
>
> I'm trying to connect some components to the ADC channels on a
Mica2. I am not using the Crossbow sensorboards, but all of the
code examples I have seen are using this sensorboard.
> The only ports I have connected are the ADC channel (ADC3) and
ground. No matter what voltage I put on the input channel, I get a
very large value (>32000) as the input for the ADC. Am I missing
something?
>
>
>
> Does anyone have an example of code for the ADC that does not use
a Crossbow sensorboard?
>
> On a related issue,
> ADC=(Vin / 1024) * Vref
> Where Vin can be between 0 and (2^6-1)*Vref and Vref is 1.23 V.
>
>
> Does this really mean that the ADC can take in voltages of up to
80V. I find that hard to believe.
>
> Thanks very much,
> Joe
>
>
>
------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
<mailto:[email protected]>
>
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help