Pages: [1]   Go Down
Author Topic: analogReference(EXTERNAL)  (Read 948 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,
       i m trying to read to the input from analog i/o and show on serial.
when i m using analogReference(EXTERNAL) function then it gives me only highest values never change that values, can anyone debug my code.

i think may be ADCMUX will be reset that would be possibility but i ll try on that way also but didn't get anything. anyone also suggest me actually what happens?? in this code.

Code:
int a = A1;
float b = 0;

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
}

void loop()
{
  b = analogRead(a);
  Serial.print("PRESSURE = ");
  Serial.println(b);
  delay(1000);
}
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2465
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A1's pinMode = INPUT ?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

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

yesh that is mistake but also same output.......

Code:
int a = A1;
float b = 0;

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(a, INPUT);
}

void loop()
{
 
  b = analogRead(a);
  b = map (b,0,1024,0,5);
  Serial.print("PRESSURE = ");
  Serial.println(b);
  delay(1000);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

erm, i may be wrong here, being newbie and all

but referring to the analog pin as A1... doest that make it behave as a digital pin ?

shouldn't it be # int a = 1; #

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
yesh that is mistake
No, it isn't. There is no way to set the mode for analog pins, because they are input only, by design.

When you use the analogReference() function, with EXTERNAL as the argument, the ADC compares the measured voltage on the analog pin to the voltage on the VRef pin. What do you have supply voltage to the VRef pin? What voltage is it?
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
yesh that is mistake
No, it isn't. There is no way to set the mode for analog pins, because they are input only, by design.

When you use the analogReference() function, with EXTERNAL as the argument, the ADC compares the measured voltage on the analog pin to the voltage on the VRef pin. What do you have supply voltage to the VRef pin? What voltage is it?

The "analog" pins 0 to 5 are also general purpose digital I/O pins (numbered 14..19) so can be set as outputs.  A6 and A7 (only on surface mount 328's) are input only.

You are right that the original problem is a lack of an external reference (BTW it has to be at least 1.1V or something like that for the ADC to behave in spec).

There is a issue here - when you press reset the Aref goes back to being internally connected to Vcc so that when you supply an external voltage to it it must be via a current-limiting resistor.  On the Arduino there is already a decoupling capacitor on Aref.
Logged

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

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

@tomperdarwin---- i tried your idea but didn't get work...any other idea???

@PaulS-- i have "ARDUINO MEGA ADK" for that i m applying 5V current with 1k variable register. so i can get ADC signal.

@MarkT--- i get your point but i dont get any idea how could i get over from this problem.
Logged

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

when i remove analogReference(EXTERNAL) this function or set default this code work properly so anyone tell me why this is happening????   

Code:
int a = A1;
float b = 0;

void setup()
{
  Serial.begin(9600);
  //analogReference(EXTERNAL);(Remove this function)
  pinMode(a, INPUT);
}

void loop()
{
 
  b = analogRead(a);
  b = map (b,0,1024,0,5);
  Serial.print("PRESSURE = ");
  Serial.println(b);
  delay(1000);
}[code/]
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you remove the analogReference(EXTERNAL), the Arduino uses it's internal 5V reference.
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There is a issue here - when you press reset the Aref goes back to being internally connected to Vcc
Actually the default state of the register should be set to EXTERNAL after a reset.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

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

Quote
There is a issue here - when you press reset the Aref goes back to being internally connected to Vcc
Actually the default state of the register should be set to EXTERNAL after a reset.

No, that is not correct:

http://arduino.cc/en/Reference/AnalogReference
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There is a issue here - when you press reset the Aref goes back to being internally connected to Vcc
Actually the default state of the register should be set to EXTERNAL after a reset.

No, that is not correct:

http://arduino.cc/en/Reference/AnalogReference
What they are saying is that by default if you perform an analogRead without specifying a reference it will default to DEFAULT.  The analogReference variable is set to DEFAULT by default but does not actually change the ADMUX register until the first analogRead takes place (probably for safety reasons just in case someone does have an external voltage applied to the AREF pin).  

We can find out for sure by simply looking at the ADMUX register after a reset and see how REFS1 and REFS0 are set (maybe I'll do this a little later if I get a chance).
« Last Edit: December 24, 2011, 12:27:38 pm by wayneft » Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There is a issue here - when you press reset the Aref goes back to being internally connected to Vcc
Actually the default state of the register should be set to EXTERNAL after a reset.

No, that is not correct:

http://arduino.cc/en/Reference/AnalogReference
What they are saying is that by default if you perform an analogRead without specifying a reference it will default to DEFAULT.  The analogReference variable is set to DEFAULT by default but does not actually change the ADMUX register until the first analogRead takes place (probably for safety reasons just in case someone does have an external voltage applied to the AREF pin).  

We can find out for sure by simply looking at the ADMUX register after a reset and see how REFS1 and REFS0 are set (maybe I'll do this a little later if I get a chance).

I went ahead and wrote a quick sketch and the ADMUX register defaults to a value of zero after a POR which is a setting of EXTERNAL.  I also changed the values to both INTERNAL and DEFAULT and hit the reset button and it resets it back to zero again. 
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

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

I would think that more important is what is the value of REFS1 and REFS0 if one performs a analogRead() statement without having performed any prior analogReference(type) command? It's the default of the analogRead() function/library that is more important rather then the hardware reset default condition and the reason it's so important to perform the analogReference(type) command before the very first usage of analogRead() command if it is to be other then using the default Avcc pin's input voltage as the reference.

Lefty


Logged

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

thanks to all to give your valuable suggestions

i think when i m calling  analogReference(EXTERNAL) function before analogRead() then they would not config with other. i mean to say may be when we call analogRead() function then REFS1 & REFS0 must be reset that's why it's give us maximum values.
apart this if we didn't call ADC library and just make myself then it's work, so i think may be any other way to work with this library or have some bug in that.
Logged

Pages: [1]   Go Up
Jump to: