Shop OBEX P1 Docs P2 Docs Learn Events
Newby questions regarding pull-down/up resistors and designing circuits... — Parallax Forums

Newby questions regarding pull-down/up resistors and designing circuits...

JedJed Posts: 107
edited 2008-01-18 00:46 in BASIC Stamp
New to BASIC stamp, just received the stamp 2 usb discovery kit and very excited so far! I have some basic questions though. I'm trying to wrap my mind around the whole pull-up pull-down resistor thing talked about in Chapter 3 (page 79). I think I understand that from the pin point of view the resister is pulling the voltage to either 5V or 0V by where it's connected. What I do not understand is why a 10KΩ is there? I figured it had something to do with protecting the STAMP because the book said that's what the 220Ω resistor was for... but on the pushbutton circuit it's only on the Vdd side and not the Vss side. So I'm confused. Also, in the back of the book (Appedix F) it talks about rules for mA on the pins being 20 Ma. So I'm assuming that there is actually no current through the pin to the Vss side? Because there's only a 220Ω resister along that path which would equate to 22.73 mA, which is above the 20 Ma limit. ?? but that doesn't make sense either Can someone please explain what's happening here?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-17 06:17
    When a Stamp I/O pin is set to input mode, the I/O circuitry senses the input voltage and indicates a high voltage for anything over about 2V and a low voltage for input below about 2V. There's nothing there to provide a default input if nothing's connected, so the input could react to noise on the board or static charges ... not good. So, a pull up or pull down resistor is added to supply a known default input voltage. The resistor can be a large value (like 10K) since the input draws only microamperes. You want a high resistance so that, when the input is connected to the other voltage (like with a pullup ... the pin is connected to ground by say a switch), the current that flows is low. If you're using a switch like a pushbutton, you probably want a current of at least a couple of hundred microamperes. 10K gives you around 1/2 a milliampere. That helps reduce the effect of noise.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-17 15:15
    The 220 ohm series resistor is there for 'accidents'. 'Accidents' like connecting one I/O pin that's driving 'high' to another I/O pin that's pulling 'low'. If there's NO resistor in there, one or the other of the driver transistors (on the BS2 PIC16C57 chip) is going to act like a fuse and burn out.

    In normal use, one I/O pin 'drives' while another I/O pin is an 'input' recieving the 'driven' signal. It's only an accident to put two 'drivers' on the same I/O wire at the same time -- and the 220 ohm resistor prevents hardware damage should that occur.
  • JedJed Posts: 107
    edited 2008-01-17 16:53
    Thank you for the very informative posts. One more question, in appendix F, I see this:

    • An I/O pin can “source” 20 mA. In other words, if you send the HIGH signal to an
    I/O pin, it should not supply the LED circuit with more than 20 mA.
    • If you rewire the LED circuit so that the BASIC Stamp makes the LED turn on
    when you send the LOW command, an I/O pin can “sink” up to 25 mA.
    • P0 through P7 can only source up to 20 mA. Likewise with P8 through P15. If
    you have lots of LED circuits, you will need larger resistors so that you don’t draw
    too much current.

    My question is on the third point. Does this mean the combination of the current that all the circuits on the group of pins together (0-7 together and 8-15 together) can not draw more than 20mA combined? If not it seems like it's just restating what the first bullet says. If I have 5mA on each pin 0-8 that's a no-no because it add up to 40mA total on that group of pins correct? Can you clarify?

    Also, just to make sure I'm understanding the way the pins work: When a pin is set to output and it's HIGH (sourcing) it's basically connecting the circuit to the battery's + terminal (Vdd) and when it's set to LOW (sinking) it's connecting to the battery's - terminal (Vss). When a pin is set to input, it's "sensing" whether the circuit is connected to Vdd or Vss. Correct? When it's an input pin there is still current passing through the pin though right? So do the terms "sourcing" and "sinking" still refer to a pin when it's in an input state and do the rules in appendix F about the mA limits still apply?

    If any of you can recommend any good books for a beginner on the rules of circuit design I would greatly appreciate it. I've got a "dummies" guide to electronics but it doesn't go into much detail beyond basics and giving you schematics to build. I love building projects but my primary goal for getting into this is to be able to really understand circuit design myself so I can build my own. Understanding where, when and why to use resistors and how strong of resistors to use seems to be my sticking point right now.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-17 17:24
    There are separate limits on how much current an I/O pin can provide from Vdd and from ground because there are two separate transistors involved and they're built slightly differently. There's an aggregate current limit for a group of 8 I/O pins because it's set by the "wiring" capacity on the chip. There's also an aggregate current limit for the entire chip again due to the capacity of the "wiring" on the chip.

    When a pin is set to input mode, it's a high impedance. The current flow is very small (microAmperes). The terms "sourcing" and "sinking" don't really apply (although strictly speaking they're still valid).

    The BS1, BS2 and BS2e use a PIC processor and the datasheets describing the devices are available from MicroChip. The other Stamps use an SX processor and those datasheets are available from Parallax.
  • JedJed Posts: 107
    edited 2008-01-17 19:39
    Ok, makes sense. On the current limits I'm running into an apparent contradiction in the book/example, but I'm sure I'm wrong somewhere in my figuring/understanding: on page 172 of the "What's a microcontroller?" book it shows a schematic for a project using the 7-segment LED component. Pins 8,9,10,11,12,13,14,15 are connected to the led with a 1kΩ resistor on each pin. So the LEDs on each pin use 1.6V out of each line... that leaves 3.4V over the 1000Ω resistor which take the current to 3.4mA per line. the pins are all in one group per the current restrictions listed in the appendix so that puts a total of 27.2 mA of current on the group if all 8 pins are sourcing at the same time or 23.8 if 7 are sourcing. Either way that's over the 20 mA limit per group. Where am I gong wrong on my calculations?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-17 20:01
    Jed,

    The limitation per group (or Port, rather) is not 20 mA/25 mA...It's 40 mA Source and 50 mA sink per port. One other thing to consider is that in most cases, not all LEDs on a 7-Segment display will be on at the same time. Nonetheless it is within tolerance of the specifications. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-17 20:06
    The input pin to the Stamp has resistance therefore it will have voltage drop, say the voltage drop at 2.5 milliamp were 0.9 volt then the other 2.5 volt would drop across the 1k resistor , 2.5 milliamp x 8 =20 milliamp

    Jeff T.
  • Lee HarkerLee Harker Posts: 104
    edited 2008-01-17 21:06
    Jed,

    Actually when a Stamp pin is configured as an input, the terms source and sink still apply but not to the Stamp.·It would be in reference·to the device that is driving the Stamp input. The device supplying the signal must be able to source or sink the current necessary to drive the input which is almost nothing.
  • JedJed Posts: 107
    edited 2008-01-17 22:46
    Ok perfect. My confusion was over the 20/25mA limits the book placed on the ports, good to know that's a typo and that they are really 40/50mA.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-01-17 23:36
    Jed -

    Just for my own satisfaction, and so that no Stamps get fried due to a typo or misunderstanding, let me state the I/O current limitations this way for the PBASIC Stamp BS-2:

    Ampacity per INDIVIDUAL pin port (1 pin)
    · Source···· Sink
    ·· 20 mA·· 25 mA

    Ampacity per ENTIRE I/O port (8 pins)
    · Source····· Sink
    ··· 40 mA·· 50 mA

    BOTH limitations MUST be considered. They are NOT mutually exclusive.

    Now I'm happy :-)

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Veni, Vidi, Velcro! - I came, I saw, I stuck around!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-18 00:28
    This is the case with any device that has multiple output drivers. Take the ULN2803 Darlington Array for example. Each output is capable of sinking 500 mA, however that rating is superceded by the total power dissapation. Because of this you cannot run all 8 outputs at 500 mA. On any device the datasheet should list the maximum current source/sink per output as well as the total power dissapation. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-18 00:44
    I think you're confusing "independent" variables and "inherent current limiting", and "max device limits before damage occurs".

    "Thank you for the very informative posts. One more question, in appendix F, I see this:

    • An I/O pin can “source” 20 mA. In other words, if you send the HIGH signal to an
    I/O pin, it should not supply the LED circuit with more than 20 mA.
    • If you rewire the LED circuit so that the BASIC Stamp makes the LED turn on
    when you send the LOW command, an I/O pin can “sink” up to 25 mA.
    • P0 through P7 can only source up to 20 mA. Likewise with P8 through P15. If
    you have lots of LED circuits, you will need larger resistors so that you don’t draw
    too much current.
    "
    1. An I/O pin can "source" 20 mA WITHOUT DAMAGE. It CAN source much MORE than 20 mA for a short time before the output transistor burns out -- which is NOT something you want to have happen. An I/O pin does NOT have any inherent current limiting feature on it. So, whatever you do, don't try to drive a load with more than 20 mA (at 5 volts, that means any load with a resistance of less than 250 ohms. Okay, 220 ohms will work).

    2. An LED does not have any inherent current limit on it either. It CAN have 25 mA go through it for a short time before the LED burns out -- again, NOT something you want to have happen. So it's CRITICALLY IMPORTANT you put some current limiting resistor in the line with the LED and the I/O pin. 470 Ohms makes a good one for red LED's.

    3. If you DO have 'lots of LED circuits', you can only have a certain number of the LED's on at the same time. It's up to you to limit the number you turn on, such that the BS2 is only sinking or sourcing 50 mA -- I'm not sure what happens if you try to source or sink more than 50 mA with the BS2 -- but hardware destruction is likely.

    Finally -- these 'current ratings' are LIMITS of DESTRUCTION. There's nothing about the device to prevent destructive currents from going through it. So you, as a builder, MUST design your circuits so they DO NOT take that much current from the BS2.· And the typical, very simple way to do this is to add a single resistor of the appropriate value (220, 330, 470 ohms are common) to limit the current from the BS2 and through the LED.

    Post Edited (allanlane5) : 1/18/2008 12:49:32 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-18 00:46
    Oh, and a pin set for "INPUT" has a VERY HIGH input impedance (on the order of 10 MegOhm). So it takes VERY little current for the Input to sense if the input signal is high or low.
Sign In or Register to comment.