We are currently using an ATmega328P as a stand alone MCU. My friend, has done a very stupid thing and connected the AREF pin of atmega328p to ground directly! Now, I was wondering if using analogReference(INTERNAL) or analogReference(DEFAULT) will help me to still read the correct analog values?!
Many Thanks
Edit: I realized the reason for my analog pins being dysfunctional was indeed the connection between AREF and ground, and it was nothing I could do except disconnecting the connection. So I broke the AREF pin (MCU was mounted on a PCB board and I had no other choice) and using the default analog reference everything is working fine now. Thank you everybody for your helps.
That's for you to try.
INTERNAL (~1.1volt) might still work.
If you only need default Aref (5volt), then connect the Aref pin to the VCC pin, and set Aref to EXTERNAL in setup().
If it works, it works. If not, you need another chip.
Leo..
AREF is connected to whatever you are using as the reference for the ADC. If it is the internal 1.1 or 2.56V reference, then that, or if you select the default then AREF pin is connected internally to Vcc.
The only safe setting is analogReference(EXTERNAL).
Until the pin is removed from ground don't call analogRead() without first setting EXTERNAL. And no, you
cannot use the ADC with is reference forced to 0V.
Normally you would add a decoupling capacitor between AREF and ground to reduce noise in the ADC, and
unless using an actual external reference that's the only connection to the AREF pin.
It's not connected now, right? The ADC isn't going to work with the reference grounded...
The datasheet says:
Note that
VREF is a high impedance source, and only a capacitive load should be connected in a system.
"High impedance" implies that very-little current will flow and you should be OK (no permanent damage).
If you were configure it to use an external reference, it would be perfectly OK (and perfectly useless) to ground Vref. ...If you were using an external reference, the internal & external references would be shorted for a period of time until your initialization routine gets it configured so that's a hint that it should be OK to short it to ground or some other reference.
DVDdoug:
If you were using an external reference, the internal & external references would be shorted for a period of time until your initialization routine gets it configured so that's a hint that it should be OK to short it to ground or some other reference.
It is NOT true. Default reference in ATMega is external. Arduino IDE switches it silently to AVcc. It is not a proof it is OK to short the reference to anything. The datasheet says
"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."
EDIT: clarification of "Arduino IDE switches it silently to AVcc." from a PM:
Paul__B:
But you should mention, not until AnalogRead is called without a pre-defined selection.