Pages: [1]   Go Down
Author Topic: Arduino Bandgap Reference  (Read 1585 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.. smiley-lol smiley-lol smiley-lol.......?

Thanks Neil.
Logged

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

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
Logged

Ontario
Offline Offline
God Member
*****
Karma: 20
Posts: 835
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

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:

Quote
//**********************************************
// 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); 
}

Logged

Ontario
Offline Offline
God Member
*****
Karma: 20
Posts: 835
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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:
analogReference(INTERNAL);

    :
    :

result = analogRead(0);
Logged

Plano, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

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

Problem solved ... Just incase any1 else wants to know i found this : http://code.google.com/p/tinkerit/wiki/SecretVoltmeter

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);
 }
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Or they could have read my reply #3 yesterday.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.   smiley-wink
Logged

Pages: [1]   Go Up
Jump to: