I am using the following code to provide a stable Vcc reference for Analog Reads . Picked up the code from this forum ..
/*
The function getBandgap() is to calculate the actual Vcc of the
MCU by using the internal reference of the MCU which is earlier measured
by uploading the sketch below and then measuring the Vref pin :
void setup ()
{
ADMUX = _BV (REFS0) | _BV (REFS1);
}
void loop () { }
Once you get the Vref actual volts, plug that into the Bandgap() function.
*/
// Function to return the Vcc Volts x 100 to maintain precision
int getBandgap(void) {
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const long InternalReferenceVoltage = 1078L; // Adjust this value to your MEGA boards specific internal BG voltage x1000
ADMUX = (0 << REFS1) | (1 << REFS0) | (0 << ADLAR) | (0 << MUX5) | (1 << MUX4) | (1 << MUX3) | (1 << MUX2) | (1 << MUX1) | (0 << MUX0);
#else
const long InternalReferenceVoltage = 1077L; // Adjust this value to your 168/328 boards specific internal BG voltage x1000
ADMUX = (0 << REFS1) | (1 << REFS0) | (0 << ADLAR) | (1 << MUX3) | (1 << MUX2) | (1 << MUX1) | (0 << MUX0);
#endif
delay(10); // Let mux settle a little to get a more stable A/D conversion
ADCSRA |= _BV( ADSC ); // Start conversion
while ( ( (ADCSRA & (1 << ADSC)) != 0 ) );
int results = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L; // Scale the value
return results;
}
The problem is when I measure Aref pin with reference to GND, I am reading 4.63 V. I think it should measure around 1.1V ? Is the board cooked ??