PDA

View Full Version : I/O Pin Voltage/Current Requirements



Bill M.
05-25-2005, 06:39 AM
I am new to the Basic Stamp, and I am trying to read a switched voltage on an I/O pin using the BUTTON function.I want to be clear of how the i/o pins work. The specifications say that each pin can sink/source ~25mA, and I read that each pin has an input impedance of 1Mohm. If the input impedance is so large, then why can't I directly connect the switch from Vdd to the pin? It seems to me that with the given input impedance, the input current should be on the order of a uA (Vi/Ii = Ri = 10^6). I would like to use the Button function to branch when Vdd is switched to the I/O pin. I noticed in the 'What's a Microcontroller' book that they prefer to implement button switches to correspond to logic 0. Can anyone clarify this for me?

Jon Williams
05-25-2005, 06:56 AM
Either (active-high or active-low) is okay ... though active-low inputs are more commonplace in designs. I was once told that the reason for this is that we'd rather have a static discharge from the user be dumped into the ground side of the circuit than the supply side of the circuit.

If what you're wanting is a variable (bit) to be 1 when the input is active, you can do this with an active-low circuit:

theBtn = ~IN0

The tilde operator inverts the variable it's attached to, so when the actual input is zero (active), the value moved into 'theBtn' will be 1. What is important is to pull the input pin to the opposite state (usually through 10K) so that the high-impedance input of the microcontroller is not affected by noise. And we recommend a 220-ohm inline resistor to protect the pin in the even of a programming error (that causes the pin to be a driven ouput when the button is pressed).


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 5/26/2005 1:49:10 PM GMT

Nav
05-26-2005, 08:32 PM
Jon,

You say that a 220 Ohm inline resistor is recommended to protect the pin in the event of a programming error that makes the pin an output.I understand the need for the inline resistor but am unsure of the value. Your post says 220 Ohm but your attached diagram shows a 220 KOhm inline resistor. I would have though 220 Ohm would be too low and 220 KOhm too high. I always beleived - and my reasoning for this may be wrong - that the correct amount was about 1 KOhm. How does one calculate the value of this inline resistor ?

Regards,
Nav.

Jon Williams
05-26-2005, 08:39 PM
Sorry, that's an error in my schematic and I will fix it right away -- sorry about that. It should be 220 ohm, not 220K. There is not magic to the value, other than 220 will give you enough protection. You could also use 470 or 1K. We use 220 because it provides enough protection and doesn't adversely affect the pin when uses as an output (RCTIME, for example, requires that the pin get used as both an output [cap charge] and input [measure discharge time]).

Update: I've attached a corrected schematic to the original post.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 5/26/2005 1:49:48 PM GMT

Nav
05-26-2005, 08:57 PM
Ahh, I see ! There might be times when 1 KOhm is just a little too high (when using the pin as an output as well as an input) so 220 Ohms sort of covers both situations. That makes sense. Thanks for the clarification, Jon.