go_away

Author Topic: enabling pullups on port pins  (Read 1513 times)

0 Members and 1 Guest are viewing this topic.

Offline vidamTopic starter

  • Supreme Robot
  • *****
  • Posts: 423
  • Helpful? 1
  • Robotronics.org
enabling pullups on port pins
« on: July 02, 2008, 09:35:31 AM »
I read that to enable a pullup on PORTD you can do something like this:
Code: [Select]
PORTD |= (1 << PD7)


What does it mean to enable a pullup on a pin of PORTD and how does this affect how data is R/W?


Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 332
  • Helpful? 3
Re: enabling pullups on port pins
« Reply #1 on: July 02, 2008, 12:11:36 PM »
To enable a pull up on a pin, you set the pin as a digital input and then set that pin's PORT bit high.  For example:

DDRD &= ~(1 << PD7);
PORTD |= 1 << PD7;

This is just like connecting an external pull up to the PD7 pin.  What it means is that the input is weakly pulled high, so this is what the pin will read if it is disconnected or connected to a tri-stated input.  If you drive this pin low, it will easily overcome the weak pull-up.

If you have an input that is either low or floating (e.g. a push button that shorts your pin to ground when it is pushed), you should use the internal pull up so that you get a reliable reading while the input is floating.  The pull up will have no meaningful effect on the pin if your input source has low output impedance.

- Ben

Offline vidamTopic starter

  • Supreme Robot
  • *****
  • Posts: 423
  • Helpful? 1
  • Robotronics.org
Re: enabling pullups on port pins
« Reply #2 on: July 02, 2008, 12:36:43 PM »
To enable a pull up on a pin, you set the pin as a digital input and then set that pin's PORT bit high.  For example:

DDRD &= ~(1 << PD7);
PORTD |= 1 << PD7;

This is just like connecting an external pull up to the PD7 pin.  What it means is that the input is weakly pulled high, so this is what the pin will read if it is disconnected or connected to a tri-stated input.  If you drive this pin low, it will easily overcome the weak pull-up.

If you have an input that is either low or floating (e.g. a push button that shorts your pin to ground when it is pushed), you should use the internal pull up so that you get a reliable reading while the input is floating.  The pull up will have no meaningful effect on the pin if your input source has low output impedance.

- Ben

Thanks and with no googling wha tis a tri-stated input? Is this off, momentary on, and on.


Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 332
  • Helpful? 3
Re: enabling pullups on port pins
« Reply #3 on: July 02, 2008, 12:45:47 PM »
Tri-stated means high-impedance (a.k.a. high-Z) output.  It effectively means the same as disconnected or floating.

http://www.nmscommunications.com/manuals/glossary/tristated.htm

- Ben

 


Get Your Ad Here