Pages: [1] 2   Go Down
Author Topic: Unused Analog Inputs Atmega328 - question  (Read 1560 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I am deploying a stand alone projevt and only use 1 of the analog inputs, does it provide any benefit to enable the pull up resistors on the unused pins?
I am thinking of stability more than  anything else.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It probably won't hurt. The analog reading is actually done "on command" (ie. when you do an analogRead), it isn't just reading away for its amusement. But setting unused pins to a known value is probably going to help keep noise out of the processor.
Logged


Offline Offline
Full Member
***
Karma: 2
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you Nick, So following what you said, I shouldnt add anything to the current draw either? The device is battery operated.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well you could put in pull-down resistors to tie them low. That shouldn't consume much, if anything. Pull-ups will add to the current drawn (as you would expect) according to my measurements here:

http://www.gammon.com.au/forum/?id=11497
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can save substantial amounts of power by just running from 3.3V rather than 5V, BTW.
Logged


Offline Offline
Full Member
***
Karma: 2
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, that is a great article, thank you.
I am using my own board in my device si it has no USB,
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well you could put in pull-down resistors to tie them low. That shouldn't consume much, if anything. Pull-ups will add to the current drawn (as you would expect) according to my measurements here:

http://www.gammon.com.au/forum/?id=11497

Actually, I'm not sure I would expect pull-ups to add to the current drawn, if nothing else is connected to the pins. Where is the current flowing to?

In fact, in my experimenting with sleep modes, I make all the pins inputs and enable pull-ups before going into power-down mode, and supply current waffles around between 0.1µA and 0.2µA.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

According to my measurements on the page quoted above, the difference is about 0.9 uA.

I presume where the current is "going" is making the input MOSFETs "work harder" by amplifying noise.

See page 43 of the datasheet:

Quote
If the input buffer is enabled and the input signal is left floating or have an analog signal level close to VCC/2, the input buffer will use excessive power.

and:

Quote
An analog signal level close to VCC/2 on an input pin can cause significant current even in active mode.
Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

According to my measurements on the page quoted above, the difference is about 0.9 uA.

I presume where the current is "going" is making the input MOSFETs "work harder" by amplifying noise.

See page 43 of the datasheet:

Right, I saw the measurements, and hence the question as my results seem different. Shouldn't having the pullup turned on reduce noise? As opposed to a floating pin?

Datasheet section 14.2.6, p81, recommends enabling pull-ups to provide a well-defined level for unconnected pins.

Recently I've been thinking about starting each sketch with the following in setup():

Code:
PORTB = PORTC = PORTD = 0xFF;    //enable all pullups
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

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

Quote
an analog signal level close to VCC / 2

A pullup would put the signal level close to VCC not close to VCC divided by 2.

My results have been similar to Jack's.  For unconnected pins, I have not measured a difference between input with pullup, output low, or output high.  But my Extech multimeter may not be up to the task.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Er, yes you both make good points. The pull-up on the face of it would result in not-floating pins.

However to check, I re-measured using the board shown on the page I linked above.

First with this sketch:

Code:
#include <avr/sleep.h>
void setup ()
{
  for (byte i = 0; i <= A5; i++)
    {
    pinMode (i, INPUT);    // changed as per below
    digitalWrite (i, LOW);  //     ditto
    }  
  // disable ADC
  ADCSRA = 0;  
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
  sleep_enable();
  // turn off brown-out enable in software
  MCUCR = _BV (BODS) | _BV (BODSE);
  MCUCR = _BV (BODS);
  sleep_cpu ();  
}  // end of setup

void loop () { }

Results:

Code:
Meter: 0.11 uA
Using Dave Jones' uCurrent device: 120 nA

So, around 110 to 120 nA with pins as input and no pull-ups.

Now with the revised sketch:

Code:
   digitalWrite (i, HIGH);  //    enable pull-ups

Results:

Code:
Meter: 75 uA
Using Dave Jones' uCurrent device: 75 uA

I admit that neither figure agrees with my previously-posted results (maybe the fuses were different).

I can't explain why my figures are so different to yours, except that we must be using different hardware, and maybe different fuse settings.
« Last Edit: February 28, 2012, 10:22:33 pm by Nick Gammon » Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

However let's assume you aren't planning to sleep. Then the results are a bit different. This sketch:

Code:
void setup ()
{
  for (byte i = 0; i <= A5; i++)
    {
    pinMode (i, INPUT);   
    digitalWrite (i, LOW); 
    }
}  // end of setup

void loop () { }

Current measured: 15.3 mA.

Changing to set all pins to pull-ups gives 11.8 mA.

So in that case, we saved 3.5 mA by turning the pull-ups on.
Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

However let's assume you aren't planning to sleep. Then the results are a bit different. This sketch:

Current measured: 15.3 mA.

Changing to set all pins to pull-ups gives 11.8 mA.

So in that case, we saved 3.5 mA by turning the pull-ups on.

Pretty sure I observed something similar recently, unfortunately did not record the results. But hence the idea of starting a sketch with all pullups on. That plus a couple of my projects which have been occasionally acting a bit funny, like they're responding to capacitive effects or maybe static electricity.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

However let's assume you aren't planning to sleep. Then the results are a bit different. This sketch:

Current measured: 15.3 mA.

Changing to set all pins to pull-ups gives 11.8 mA.

So in that case, we saved 3.5 mA by turning the pull-ups on.

Pretty sure I observed something similar recently, unfortunately did not record the results. But hence the idea of starting a sketch with all pullups on. That plus a couple of my projects which have been occasionally acting a bit funny, like they're responding to capacitive effects or maybe static electricity.

On an unaltered Arduino (I have a dozen or so Pro Mini's lying around, some adulterated, so virginal ...) I see pins floating to the voltage of other pins in the same port.  For digital pins, I see them signal close to whatever is nearby -- most often around line frequency.  So, I'm guessing they are sensitive to capacitive effects (parasitic capacitance on the die, maybe?) as well as RF.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good point. Probably to get defined behaviour you should have defined inputs into the pins. I would have thought that tying a pin low through a 10K resistor would do that at minimal cost, but maybe I'm wrong.
Logged


Pages: [1] 2   Go Up
Jump to: