Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 2 I/O function — Parallax Forums

Basic Stamp 2 I/O function

DunwoodyDunwoody Posts: 2
edited 2007-11-08 17:50 in BASIC Stamp
I·am doing the projects in·the "What's a Microcontroller?" text.· I don't understand the sensing function of the I/O pins when connected to either Vdd or Vss. Because there is a resistor between Vss and the pins or Vdd (usually just a 220 Ohm) does the Basic Stamp sense 5V or 0V, current direction, or something else? I find this especially confusing when a pin is connected to Vss through a 220 and 10K Ohm resistor.·I am currently working on Chapter #3 pertaining to pushbuttons and digital input. I am new to this and have no programming experience and·a rudimentary electronics background. If somebody could explain this·I would be grateful.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-08 16:36
    Dunwoody,

    Let’s break this down into two parts…The 220 ohm resistor is simply protection on the I/O pin in the event it was accidentally set as an output. In this case the 220 ohm resistor will limit the maximum current the pin can draw while shorted to VDD / 220, or approximately 23 mA. The 220 resistor does not have any effect on the 0V (LOW) or 5V (HIGH) signal coming into the pin.

    As for the 10K pull-up (or pull-down)…depending on the switch configuration (active-high or active-low) the 10K resistor keeps the I/O line from floating when the switch is not closed. Without it the I/O pin will float and could give false readings. Because the resistance is so high it will pull the I/O line toward the supply rail it is connected to, however when the switch is closed it will allow the line to be driven to the opposite supply rail by the closure of the switch. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • DunwoodyDunwoody Posts: 2
    edited 2007-11-08 17:16
    Chris

    Thank you for the reply. That makes it clearer. Why does the 220 Ohm resistor protect the pin as an output if connected to Vdd by accident. They are both 5V aren't they? I see how it limits current to 23 mah if connected directly·to Vss by simple Ohm's law.

    If I wrote the command HIGH 14 and connected pin 14 directly to Vdd with no resistor would that be bad? Is that what the resistor protects against? I don't see how this is a short.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-08 17:46
    The problem that the resistor protects against is if pin 14 is directly connected to Vdd and you accidentally wrote the command LOW 14. This can happen, particularly if the Stamp is connected to another device that sometimes transmits to the Stamp and sometimes receives from the Stamp and your program gets things wrong and tries to transmit when it should receive and the output level is opposite to that of the other device. Another common case is when you have a switch, usually connected to either Vss or Vdd with a pullup resistor to the other voltage (Vdd or Vss). If the switch is closed and your program accidentally tries an output command ... well you get a short circuit and the Stamp pin circuitry may be damaged.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-08 17:50
    Dunwoody,

    There’s no way to know what an accidental connection or programming error would set the pin to. Setting the pin HIGH while connected to Vdd may not seem bad, but if a programming error could set the pin HIGH it could also set it LOW. And then there’s the active state of the switch. If the pin is set HIGH and the switch is active LOW, as soon as the button is pressed you have a short-circuit condition. A 220 ohm resistor is a very cost effective safety net. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.