Thursday, July 5, 2007

Pullup resistors - how and why

I was working away yesterday when I got an IM from a hobbyist friend
"I was playing with some switches and your design said to use 10K pull-up resistors, they take about 500uA of current each, why so much? Aren't pull-ups just to get a voltage?"

Well, yes and no! There are several reasons to use a pull-up resistor
  1. Establish a logical 1 input on the pin.
  2. Provide wiping current for switches.
  3. Act as a current source for something like an open-drain or open-collector output
Back in the dark ages when TTL (Transistor-Transistor Logic) ruled, logic inputs actually drew current! Not a lot, but to ensure that a pin was pulled 'high' you needed to source at least 40uA at a minimum of 2.4V. The input of a TTL circuit is typically the open emitter of an NPN transistor. So generally a value between 1K and 5K was commonly used. Todays most common integrated circuits use CMOS technology, and if the pull-up is merely to provide a logical 1 at the input then even 100K would be acceptable. Many microcontrollers such as the Atmel AVR and Microchip PIC parts have internally selectable pull-ups for convenience and reduced parts count. The actual resistance value will vary, but is often in the range of 40-80K ohms.

Switches open up a whole new ball game. The contacts of most switches are made with a highly conductive metal plating over a lower cost metal such as brass. When selecting a switch for your application check the data carefully as some types will require a minimum 'wiping' current which is needed to inhibit oxidation of the contact surface, particularly for designs where the switch contacts do not 'wipe' across each other. Once again, modern parts require lower currents, but if a switch seems to be unreliable, try increasing the current by reducing the value of the pull-up resistor.

When the resistor is used to provide the output load for an open drain or open collector circuit its value needs to be high enough to keep the current down to a reasonable value, but low enough to provide enough current to get the required speed. A perfect example is the I2C (i-squared-c) bus from NXP. A large number of inputs can appear in parallel so the pull-up needs to provide sufficient current to take all of them to the high state. And it must do so whilst charging up the input capacitance of all the devices and any parasitic capacitances in boards or cables quickly enough to get the appropriate rise times.

One common mistake I see is people using I2C with controllers and accepting the internal pull-up as being adequate for driving the bus. It just might work if the one I2C peripheral or memory part is the only thing connected to the processor and it is very close to the host. But even then many users report that they cannot get the 100kHz or 400kHz speed of the I2C bus, the might have to reduce the clock to 10kHz or even less. I2C was specified with a 4.7K pull-up for a darned good reason, and you will see that the rise times and thus speed capability of the bus only achieve optimal values when you use that pull-up.

No comments: