Go Down

### Topic: Arduino Bandgap Reference (Read 4331 times)previous topic - next topic

#### neilrudds

##### Feb 09, 2011, 09:56 pm
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.

#### retrolefty

#1
##### Feb 09, 2011, 10:34 pm
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

#### gardner

#2
##### Feb 09, 2011, 10:47 pm
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?

#### Grumpy_Mike

#3
##### Feb 09, 2011, 10:51 pm
Quote
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.

#### neilrudds

#4
##### Feb 09, 2011, 11:34 pm
Thanks for the replys: heres my circuit which i designed a few months ago:

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:

Quote

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

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

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

#### gardner

#5
##### Feb 10, 2011, 01:08 am

Code: [Select]
`  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().  http://arduino.cc/en/Reference/AnalogRead

You are going to have code more like:

Code: [Select]
`analogReference(INTERNAL);    :    :result = analogRead(0);`

#### cjands40

#6
##### Feb 10, 2011, 03:55 pm
Quote
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).

#### neilrudds

#7
##### Feb 10, 2011, 07:40 pm
Problem solved ... Just incase any1 else wants to know i found this : http://code.google.com/p/tinkerit/wiki/SecretVoltmeter

long result;   // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}

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

void loop() {
delay(1000);
}

#8
##### Feb 10, 2011, 08:05 pm
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.

#### Grumpy_Mike

#9
##### Feb 10, 2011, 08:17 pm
Quote
Problem solved ... Just incase any1 else wants to know i found this