Pages: [1]   Go Down
Author Topic: Problem with Aref  (Read 535 times)
0 Members and 1 Guest are viewing this topic.
KCMO
Offline Offline
Newbie
*
Karma: 0
Posts: 5
You can only get smarter by playing a smarter opponent.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to get the Aref pin to work so I can scale down analog input references for better resolution.  I cannot figure out what I am doing wrong here.

I am using the 3.3V supply from the Uno board through a voltage divider of 1.5M and 1K resistors.  This provides around 2.19mV.  I connect that to the Aref, and the GND below the Aref to the bottom of the divider.  No matter what I do, I cannot read anything but 1023.  I am understand the floating pin, but it doesn't go to 0 when grounded.  I have tried just connecting it to the 3.3V supply directly (to AREF), and that works.  I have tried INTERNAL and DEFAULT analog references, and they seem to work fine.  It is only when I try and scale it down that it won't read.  Also, I have tried multiple analog pins in case one was bad or something.

Divider:


Below is the code, however, I suspect there is something else going on as it work fine on a direct connection to board voltages...

Any help would be appreciated

Code:
float test;
float coeff[] = {0 , 1.978425E+2 , -2.001204E-7 , 1.036969E-11 , -2.549687E-16 ,   
    3.585153E-21 , -5.344285E-26 , 5.099890E-31};    //Type J coefficients

float temp;
float temp_comp;

long time_ref;        //time to act as start time reference (milliseconds)
long time_current;

int analogpin = A1;  //analog pin to use
int analoginput = 0;  //integer value 0-1023 input from pin



void setup(){
  Serial.begin(9600);
  analogReference(EXTERNAL);  //use AREF as voltage reference
 
  Serial.println("Anolog input testing");
 
}
 
void loop(){
  delay(2000);
  time_current = millis();  //timestamp
 // analoginput = 0;
  analoginput = analogRead(analogpin); // reads analong input pin and stores to variable
 
  test = 0;
  temp = 0;
  temp_comp = 0;
 
  test = map(analoginput, 0 , 1023 , 0 , 2150); // maps 0-1023 to 0-2150 microvolts
  test = test/1000; // converts microvolts to millivolts
 
  temp = tc_calc(test);
  temp_comp = temp + 21.222;
 
  Serial.print(time_current);
  Serial.print("\t");
  Serial.print(analoginput);
  Serial.print("\t");
  Serial.print(test);
  Serial.print("\t");
  Serial.print(temp);
  Serial.print("\t");
  Serial.print(temp_comp);
  Serial.println("");
}



// Thermocouple Calculations
float tc_calc(float tc_mv){
  int i = 0;
     while(i <=7) {
       temp = temp + coeff[i]*pow(tc_mv,i);
       i++;
      }
  return temp;
}
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
analogReference(EXTERNAL);
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.
Take a look here : http://arduino.cc/en/Reference/AnalogReference
Logged

KCMO
Offline Offline
Newbie
*
Karma: 0
Posts: 5
You can only get smarter by playing a smarter opponent.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.

I am sorry, that doesn't make any sense.  I am applying ~2.19mV at AREF, and grounding the analog input pin, I should get zero.  When I apply 3.3V at AREF and ground the analog input pin, I get 0. Similarly, when I repeat this for 5V, I get 0.  It is only when I apply the 2.2mV that I get 1023.

I forgot to mention in my first post, I tested all of this with a DVM, and I am infact getting the voltages as they should be at each pin and reference.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.

I am sorry, that doesn't make any sense.  I am applying ~2.19mV at AREF, and grounding the analog input pin, I should get zero.  When I apply 3.3V at AREF and ground the analog input pin, I get 0. Similarly, when I repeat this for 5V, I get 0.  It is only when I apply the 2.2mV that I get 1023.

I forgot to mention in my first post, I tested all of this with a DVM, and I am infact getting the voltages as they should be at each pin and reference.

That is because you failed to study/read the datasheet about the electrical specification of the Aref pin and what's it's minimum voltage can be, approx +1.0 vdc.

Lefty
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the minimum which Arduino can pick up is ~4.88mV (5/1023). If less it gets 0.
And you're saying the opposite of you first post  smiley-eek please be logical.

If you want to understand how ridiculous are your tests, draw a schema, it would help you  smiley
Logged

KCMO
Offline Offline
Newbie
*
Karma: 0
Posts: 5
You can only get smarter by playing a smarter opponent.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess that is my mistake.  I was relying on the Arduino reference guides and documentation.  I guess maybe they should consider changes there documentation from:

Quote

As indicated:
Quote
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.

to something more like (1-5V)
Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12467
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Indeed that tutorial is faulty.

The 1V limit for AREF is not a hard limit though - below that voltage they no longer guarantee the accuracy of the ADC.

I suspect you can try setting AREF to 0.5V and get less accurate results.

BTW the AREF input must be driven from a low impedance source, a voltage divider is not good enough.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: