Pages: [1]   Go Down
Author Topic: Default Input Pins to HIGH  (Read 1053 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3420
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As it was discussed here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243213127 floating input pins are a bad idea. However most users seem to be unaware of this fact. I would like to suggest that by default input pins should be pulled to high. Of course this has some implication for applications that rely on not being pulled up, so this is incompatible. On the other side the floating pins are a pain for all novice and unaware users. In my opinion the floating pins cause more harm than one would expect so this should be fixed.

Cheers, Udo
Logged

Check out my experiments http://blog.blinkenlight.net

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

Not sure I agree with your assessment. Floating inputs are only a problem if you are using them. If unused in the program, they cause no harm, but possibly raise current consumption by some micro-watts, maybe.

Lefty
« Last Edit: August 24, 2009, 01:24:52 am by retrolefty » Logged

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

i don't know about that, udo.  i'm trying firmata for the first time and floating pins seem to be wreaking havoc.  the example i'm using is watching the state of all of the pins all of the time, and they're constantly changing whenever i touch the board.

rob
Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

FWIW, Atmel recommends:

Quote
Unconnected pins
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even
though most of the digital inputs are disabled in the deep sleep modes as described above, floating
inputs should be avoided to reduce current consumption in all other modes where the digital
inputs are enabled (Reset, Active mode and Idle mode).

The simplest method to ensure a defined level of an unused pin, is to enable the internal pullup.
In this case, the pullup will be disabled during reset. If low power consumption during reset is
important, it is recommended to use an external pullup or pulldown. Connecting unused pins
directly to VCC or GND is not recommended, since this may cause excessive currents if the pin is
accidentally configured as an output.

b
Logged


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

If a pin is wired to be an output, wouldn't enabling the pullup be almost the same as turning the pin high?  Wouldn't 5v be present on the pin when the pullup is enabled?
Logged

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

Quote
If a pin is wired to be an output, wouldn't enabling the pullup be almost the same as turning the pin high?

Yes, if a pin is programmed (not wired) to be an output pin then the concept of pull-up is not applicable. The pin will either be high or low depending of the state of the pin's data output register, even if there is nothing wired to the pin. The same register used to hold pin output data is used to enable pull-ups if the pin is programmed to be an input pin.

 Pull-ups or pull-down is an input pin conditioning thing to ensure that there is a predefined voltage level applied to the pin to give it a predictable high or low voltage level.

Lefty
Logged

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

In that case, is defaulting pins to have the internal pullups enabled a good idea?

I apologize if I'm beating a dead horse, but I want to make certain I understand.  
Logged

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

Well that's kind of a personal choice kind of thing. Posted in this thread is an Atmel recommendation to enable internal pullups on unused input pins. Although the reasons stated have more to do with battery power and sleep mode benefits.

Bottom line? I've read over hundreds of sketches in this form and at least as many in the Arduino web site. I don't EVER recall seeing a sketch  where they have enabled pull-ups on UNUSED input pins.

So I don't do it, but certainly don't recommend not doing it, it's really your choice. It doesn't add much overhead as it can be done just once in the setup code. And if you were to use direct port access coding you could do all unused pins in just a few lines of code.

Lefty
« Last Edit: September 18, 2009, 11:48:03 pm by retrolefty » Logged

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

I think we're talking past each other.  Let me try rephrasing...

In that case, is having the Arduino startup code default pins to have the internal pullups enabled a good idea?  In other words, is Udo's idea a good idea?

Assuming I understand, it sounds as though the idea is not good.  That a device connected to a pin could "accidentally" be turned on by the startup code turning on the internal pullups.  If this is the case, it would not only be a bad idea but it would create a potentially dangerous situation.
Logged

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

Quote
I think we're talking past each other.

I have nothing else or new to add, sorry. It's just not a big deal in my book either way.  :'(


Lefty
Logged

0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3420
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I considered this again after playing around with two interconnected arduinos.

The following is what I found:

1) floating input pins will increase power consumption
2) floating input pins will show up with erratic values (no surprise)

With (1) and (2) and the datasheet, pulling up looks like a good idea.

3) Pulling up pins by default will connect the pullup resistor to the power rail, hence if the pin is pulled high from outside, then the arduino will get some power through the pullup even if the arduino is not directly connected with power. This in turn may lead to unexpected behavior as well.

Considering (1), (2), (3) I think my initial suggestion will just shift the issues around instead of solving all of them. Hence a change to the libraties is probably not such a good idea. However I think the issue should be documented somewhere.

Cheers, Udo


Logged

Check out my experiments http://blog.blinkenlight.net

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wen using digital outputs to drive external circuitry (e.g. a transistor power switch, on/off motor controller, etc.) we typically need to add an external pull-down resistor to make sure whatever is connected remains idle/safe during power on, reset or whenever our software is not in control.

If the Arduino core was modified to force the level opposite of what my design dictates (pull-up as suggested here), this would be undesired. Leaving defaults as is (floating) gives me the option to force logic level either way without conflict.
Logged

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

Quote
Wen using digital outputs to drive external circuitry (e.g. a transistor power switch, on/off motor controller, etc.) we typically need to add an external pull-down resistor to make sure whatever is connected remains idle/safe during power on, reset or whenever our software is not in control.

 A very good point. Especially when the Arduino output pin is directly driving a logic level N channel MOSFET to switch a high current and/or high voltage load.

 If there is not a external pull-down resistor on the MOSFET gate to ground then there is a good chance that whatever load the MOSFET is switching will turn on erratically if the Arduino is powered off or reset or during a new upload. The resistor is better placed directly at the MOSFET location rather then at the Arduino output pin.

Lefty
« Last Edit: September 19, 2009, 10:20:31 am by retrolefty » Logged

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

BenF: Thanks for the post.  That's what I was trying to say but obviously didn't do to well!  I'm glad you were able to communicate the potential problem.
Logged

Pages: [1]   Go Up
Jump to: