Arduino Bandgap Reference

Hi, Hope someone can help probably basic electronic but cant figure it out.....

I want to measure the VIN voltage to my board and ive written the code ok but it needs compensated for the fact i have a 10K resistor connected on pin 14! therefore if in input:

4.87V i get a bandgap ref reading of 3.30V as ive lost 1.57V accross the 10K resistor @ 0.487 mA
or 4.22V i get a reading of 3.01V due to the loss of 1.21V accross the 10K resistor @ 0.422 mA

can anyone derive a formula to compensate for this and correct for different values.. XD XD XD.......?

Thanks Neil.

Your verbal discription is not real clear to me. What is needed is a simple schmatic drawing of how you have wired everything up and the values of the components. I'm not sure at all that you are using the term band-gap properly.

Lefty

It would help if you could draw a circuit and explain more carefully what you are trying to do. I think what you are saying is that you want to be able to build a voltage divider that will enable you to measure your main Vin voltage, using the Arduino built-in 1.1V A2D reference. Is that correct?

i have a 10K resistor connected on pin 14! therefore if in input:

Why?
There is no need to wire anything to anything. You need to write software to access the analogue multiplexers above 7. One of these is the internal band gap. By measuring that with Vcc as the reference you can work out what the value of Vcc is.

Thanks for the replys: heres my circuit which i designed a few months ago:

http://www.neilrudds.co.uk/wp-content/uploads/2011/01/PCB.png

origionally I wasnt aware of the bandgap ref feature until i came accross a youtube vid.

As you can see on pin 14 there is a 10K resistor which is connected to ground, will this effect the V Bandref?

What im trying to do is get the VIN value, but when I input 4.87V i get a reading of 3.30 Volts! and i dont kno why?

Here is my code:

//**********************************************
// Get the Vin see pin(14) on datasheet
//**********************************************

int reference; // Stores Refrence val
float VIN; // Stores the Input Voltage

void Get_VIN(void)
{
reference = analogRead(14); // 1.1Volts!
VIN = ((1.1/reference)*1023); // Convert to VIN , 1.56 dropped accross R4 10K
Serial.println(reference);
Serial.println(VIN);
}

neilrudds:

  reference = [color=#CC6600]analogRead[/color](14); [color=#7E7E7E]// 1.1Volts![/color]

I suspect you may be mixing up Arduino pin numbering with ATMEL AVR ping numbering. Arduino (on a 168) doesn't have an analogue input numbered 14. Please have a look at the reference manual for analogRead() and analogReference(). analogRead() - Arduino Reference

You are going to have code more like:

analogReference(INTERNAL);

    :
    :

result = analogRead(0);

I suspect you may be mixing up Arduino pin numbering with ATMEL AVR ping numbering. Arduino (on a 168) doesn't have an analogue input numbered 14.

Actually, "14" is the correct ADMUX value to read the internal bandgap voltage but the Arduino analogRead function no longer allows access to it (as of IDE 18, I believe).

Problem solved ... Just incase any1 else wants to know i found this : Google Code Archive - Long-term storage for Google Code Project Hosting.

long readVcc() {
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}

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

void loop() {
Serial.println( readVcc(), DEC );
delay(1000);
}

Bear in mind that the constant...

result = 1126400L / result; // Back-calculate AVcc in mV

...varies a bit from processor to processor. If you need an accurate VCC value, you will have to determine the actual bandgap voltage for your processor.

Problem solved ... Just incase any1 else wants to know i found this

Or they could have read my reply #3 yesterday.

Or they could have read my reply #3 yesterday.

The destination isn't nearly as important as the journey. @neilrudds just wanted to take the long scenic route. :wink: