Pages: 1 [2] 3   Go Down
 Author Topic: Uno Reference Voltage of 1.1v  (Read 960 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 27
 « Reply #15 on: January 17, 2013, 08:29:34 pm » Bigger Smaller Reset

No my source is ~5v.   My reference voltage is 1.071v

So you'll be using the technique described in that post?  Using the battery voltage as a reference to measure the 1.071V bandgap?

Yes, it seems to be working.  The value I am getting off my battery with a multimeter though is 5.28v, but the value I am getting using the second technique in that post is 3.53v (I get 5.0v if I power it off USB).  Does that sound right?

Basically, I am trying to accurately log battery level for my project.  But as a side, I am trying to make sure my analogue values captured are accurate.
 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #16 on: January 17, 2013, 08:40:17 pm » Bigger Smaller Reset

The value I am getting off my battery with a multimeter though is 5.28v, but the value I am getting using the second technique in that post is 3.53v (I get 5.0v if I power it off USB).  Does that sound right?

Uh, no.  If you're using the correct code / method, you should be getting a value very close to 528.  Even if you're using 1.1V for the bandgap voltage you should be getting much much closer to 528 than 353.

Are you planning to power the processor directly from the battery?

How do you have the battery connected?

(I'll have some software questions when I'm in front of the other computer.)
 Logged

Offline
Newbie
Karma: 0
Posts: 27
 « Reply #17 on: January 17, 2013, 09:16:09 pm » Bigger Smaller Reset

I have 4 x AA batteries connected to the barrel connector.   And I have AREF connected to 5v.

Aside from that I am running a SD Logger, so I can see the values.

Here is my code:

Code:
const long InternalReferenceVoltage = 1071L;  // Change this to the reading from your internal voltage reference

void setup( void )
{
Serial.begin( 115200 );
Serial.println( "\r\n\r\n" );

// REFS1 REFS0          --> 0 0 AREF, Internal Vref turned off
// MUX3 MUX2 MUX1 MUX0  --> 1110 1.1V (VBG)
ADMUX = (0<<REFS1) | (0<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
}

void loop( void )
{
int value;

// Start a conversion

// Wait for it to complete

// Scale the value
value = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;

Serial.println( value );
delay( 1000 );
}

Here is my output:
~350 is 4 x AA (5.28v on multimeter) connected to Barrel jack.  500 is USB connected from computer.
Code:
351
358
357
357
356
357
356
356

500
500
500
500
500
500
500
500
500
 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #18 on: January 18, 2013, 12:23:50 am » Bigger Smaller Reset

I have 4 x AA batteries connected to the barrel connector.

With Vcc regulated to 5V, why aren't you: using Vcc as the reference, a voltage divider to get the battery voltage in range (I'd just cut it in half), and measuring that in the plain-ol-analogRead fashion?

The code you are trying to use was meant for a processor running directly from batteries.  I don't think it functions correctly the way you are trying to use it (AREF > Vcc).
 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #19 on: January 18, 2013, 12:30:22 am » Bigger Smaller Reset

Time for a sanity check...

value = (((InternalReferenceVoltage * 1024L #) / ADC) + 5L) / 10L;

528 = (((1071 * 1024) / ADC) + 5) / 10
5280 = (((1071 * 1024) / ADC) + 5)
(5280 - 5) = ((1071 * 1024) / ADC)
ADC * (5280 - 5) = (1071 * 1024)
ADC = (1071 * 1024) / (5280 - 5)

The ADC value should be within a reasonable range.  Try printing it as well...

Code:
void loop( void )
{
int value;

// Start a conversion

// Wait for it to complete

// Scale the value
value = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L;

Serial.println( value );
delay( 1000 );
}

# The correct value is actually 1024.
 Logged

Offline
Newbie
Karma: 0
Posts: 27
 « Reply #20 on: January 18, 2013, 12:47:18 am » Bigger Smaller Reset

Thanks for all your help.  I actually have no idea how I started down this path.  The main thing I want to do is log my voltage of my source batteries.  As such, a Voltage Divider (http://en.wikipedia.org/wiki/File:Resistive_divider.png    = 2 resiters of the same value).  Then send VOut to A0, and read the value, then double it.  Sound right?

Do I even need a reference value?

But then, since I know the reference value now anyway.  And my reference voltage is 2% out from 1.1v.  As such, should I treat any value coming into A0 to A5 as being 2% too low?    Its only 2%, I don't think I care that much as most of my connections are Digital anyway, and everything anyway seems to have different levels of accuracy.  More curious now.
 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #21 on: January 18, 2013, 01:00:47 am » Bigger Smaller Reset

Then send VOut to A0, and read the value, then double it.  Sound right?

Yes.  You could optionally add some calibration to get a more accurate value.

Quote
Do I even need a reference value?

Technically, you always have a reference.  In this case you would use the default which is Vcc (regulated 5V).

Quote
And my reference voltage is 2% out from 1.1v.

The bandgap / 1.1V reference would no longer be involved.  You can forget about it.

The reference you would be working with is Vcc / 5V.
 Logged

Offline
Newbie
Karma: 0
Posts: 27
 « Reply #22 on: January 18, 2013, 01:27:09 am » Bigger Smaller Reset

Quote
And my reference voltage is 2% out from 1.1v.

The bandgap / 1.1V reference would no longer be involved.  You can forget about it.

The reference you would be working with is Vcc / 5V.

Thanks.  So in theory, if my VCC drops to 4.8v, I should multiply every value in A0-A5 by 1.041 to get its real value, assuming that item is a 5v item ?

Is there a real way to test this?
What if I get my 5v battery power source, measure VCC @ I assume 5v.  Measure a 1.5v AA battery on A0.   Then let the arduino power batteries go flat.  When VCC gets to 4.8v, take a second reading from A0, and it should be 4% lower ?  Maybe?

How low can the source arduino power get before it will no longer function?
 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #23 on: January 18, 2013, 02:52:13 am » Bigger Smaller Reset

How low can the source arduino power get before it will no longer function?

I have no idea.  Some folks claim just north# of 6V is required on Vin but your testing contradicts that.

Quote
So in theory, if my VCC drops to 4.8v,...

In theory, that would be impossible.  It's a 5V low dropout regulator so the cutoff should be at 5V.

Quote
Is there a real way to test this?

The first course of action is to get an opinion from someone who understands the switching circuit and voltage regulator (someone who isn't me).  If you don't get a reply in a reasonable amount of time, I suggest posing your question in the General Electronics section (or spend some time searching the forum; I believe the topic has been discussed).

# For those living in the Southern Hemisphere that would be "just above".
 Logged

Offline
Newbie
Karma: 0
Posts: 27
 « Reply #24 on: January 21, 2013, 05:48:01 am » Bigger Smaller Reset

For anyone else looking, I think this gives me what I need:   http://arduinotronics.blogspot.com.au/2011/03/monitoring-voltage-of-dc-battery-supply.html
 Logged

0
Offline
Newbie
Karma: 0
Posts: 27
Arduino rocks
 « Reply #25 on: January 28, 2013, 04:04:11 pm » Bigger Smaller Reset

just want to add my two cents - I am researching how to measure battery voltage through the bandgap method

if you connect the batterys to the vin barrel - you are not going to get the same voltage on vcc - far from it. The battery voltage goes through the voltage regulator. If at all possible - hook up your battery pack to vcc. (assuming it is not over 5.5 volts and not reversed!)
So the results you measure may actually be correct

hooking up an arduino to usb does bypass the voltage regulator
however - this does not garantuee a clean 5v vcc
when I hook my arduino up to a usb 1.1 hub - I get around 4,3 volts on vcc
it took me quite some time figuring out why analog temperature sensors would give bad results. I finally figured out a simple trick, measure the 3,3v line on an analog pin and use that to calculate the voltage on Aref. This did cost me an analog pin. I am looking into the bandgap method for future projects.

Thanks to coding badly and lefty for some great posts on the subject.

May I point to another great source on this subject?

http://jeelabs.org/2012/05/04/measuring-vcc-via-the-bandgap/
http://jeelabs.org/2012/05/12/improved-vcc-measurement/
 Logged

Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
 « Reply #26 on: January 28, 2013, 04:18:14 pm » Bigger Smaller Reset

Quote
when I hook my arduino up to a usb 1.1 hub - I get around 4,3 volts on vcc

That is quite low, and below the USB standards of I think 4.75 to 5.25. Try plugging directly into one of your PC's usb ports instead of that hub and see if you don't get a more normal Vcc value.

Lefty
 Logged

0
Offline
Newbie
Karma: 0
Posts: 27
Arduino rocks
 « Reply #27 on: January 28, 2013, 04:37:30 pm » Bigger Smaller Reset

way ahead of you there ...
when I use the computers usb ports all is fine!
just this usb 1.1 hub
I have not looked into it that much further - it doesnt bother me since I figured out a way to measure the vcc
which actually was a good idea since I need this when I want to run my arduino off batteries.

I just got fascinated by the whole bandgap idea because it doesnt involve sacrificing an analog pin.

 Logged

Global Moderator
Dallas
Online
Shannon Member
Karma: 118
Posts: 10167
 « Reply #28 on: January 28, 2013, 06:34:30 pm » Bigger Smaller Reset

ARGH!  It's 1024!

Quote
if you connect the batterys to the vin barrel - you are not going to get the same voltage on vcc - far from it. The battery voltage goes through the voltage regulator.

It that situation, use the regulated 5.0V (or 3.3V) supply on the Arduino as a reference and a voltage divider on the battery to get the voltage in range.

Quote
however - this does not garantuee a clean 5v vcc

Use the regulated 3.3V as a reference.

Quote
when I hook my arduino up to a usb 1.1 hub - I get around 4,3 volts on vcc

Yikes!  You need to drop that thing for a powered hub.  In my experience, this one is well worth the money...
http://www.usbgear.com/computer_cable_details.cfm?sku=USBG-7U2ML&cats=104&catid=104%2C653%2C210%2C212

Quote
I finally figured out a simple trick, measure the 3,3v line on an analog pin and use that to calculate the voltage on Aref.

Or just use the 3.3 V as the reference.

Quote
Thanks to coding badly and lefty for some great posts on the subject.

You are welcome.
 « Last Edit: January 28, 2013, 08:53:45 pm by Coding Badly » Logged

Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
 « Reply #29 on: January 28, 2013, 07:57:29 pm » Bigger Smaller Reset

way ahead of you there ...
when I use the computers usb ports all is fine!
just this usb 1.1 hub
I have not looked into it that much further - it doesnt bother me since I figured out a way to measure the vcc
which actually was a good idea since I need this when I want to run my arduino off batteries.

I just got fascinated by the whole bandgap idea because it doesnt involve sacrificing an analog pin.

Your welcome, and bandgaping was fun but CB did most of the heavy lifting. I just wanted to see if it could be useful or not and wouldn't stop bugging him for help and ideas. To tell the truth I almost never find my projects using all the analog input pins (and if so I just switch to the mega board or my 644P soon to be 1284P board, so just tying the 3.3v to a AI pin and using that as a compensation/refence value is simple enough. Heck on one of my boards I have a jumper from the anode of the power led wired to a AI pin as a reference, it works.

But for serious ADC results I just use I2C ADC chips, either the TI 12 bit ADS1015 for 16 bit ADS1115, they are what real ADC is be all about. Adafruit has some nice breakout boards for them and has support library all set to go.