9
\$\begingroup\$

I want to understand the concept of open-drain ports like port P0 of the 8051 microcontroller. Why do we need to connect pull up resistors to the port P0?

I have basic knowledge of MOSFETs and other electronic devices.

\$\endgroup\$
1
  • \$\begingroup\$ okay so what i understand is it basically functions like any other port but we have to give the power supply thru some external source . Am i right ? \$\endgroup\$
    – abkds
    Commented Jun 4, 2013 at 9:33

4 Answers 4

13
\$\begingroup\$

Ignoring the ins and outs of how mosfets work. The output acts like a switch to ground. It cannot produce a high (+5V) signal by itself. The pull up resistor is used so that when the switch is open the output will be high. When the switch is closed the output will be low (0V)

enter image description here

\$\endgroup\$
9
\$\begingroup\$

There are two common applications of open-drain (or open-collector, in the case of BJTs):

1) Connecting more than one output to the same line. This is called a wired-OR. For example, you may have a normally high reset pin on a device, which is reset from both a microcontroller pin and another source, say a pushbutton. The reset pin is tied high with a pull-up resistor. The microcontroller is configured as an open-drain output. The pushbutton is tied to ground when pushed. If either the microcontroller pulls its output to 0, or the pushbutton is pressed, the device will be reset.

Note that when the microcontroller sets its output pin to 1, the pin is in effect disconnected from the line. It is not driving the line ("sourcing") with any voltage, so when the pushbutton pulls the line to ground, there is no short.

Because wired-OR configuration is so useful, this is why pins such as resets on a microcontroller, interrupt lines, clear and enable lines on devices such as flip-flops, are all "active low" - meaning they are normally tied high (again, via a pull-up resistor), and any of several devices configured as open-drain may pull them low. Such inputs are usually designated as active-low with either a bar across the top of the signal name, or a leading ! (!CLR), or a trailing # sign (CLR#).

2) Controlling devices connected to different supply voltages. Say you have a relay that requires 20 mA, but a voltage of 5 volts. But your microcontroller output can only drive pins up to its power supply (VCC) voltage of 3.3v. With an open-drain output, you can connect one side of the relay to 5 V, and the other to the output pin of the microcontroller. When the output of the microcontroller in is 1, nothing happens (again, acts like the pin is disconnected). When it is set to 0, this grounds the bottom side of the relay completing the circuit and operating the relay. In such an application, it is important to place a "fly-back" diode across the relay coil to prevent damage to the microcontroller when the device is de-energized.

For output drivers like the ULN2803 (Darlington transistor array), you can drive loads connected to voltages as high as 50 v and control them with a logic compatible input.

\$\endgroup\$
4
  • \$\begingroup\$ a microcontroller can often sink more current (drive to ground) than it can source (drive to the VCC of the microcontroller) That isn't true anymore with modern CMOS microcontroller \$\endgroup\$
    – m.Alin
    Commented Jun 4, 2013 at 10:56
  • 1
    \$\begingroup\$ Your second use case seldom applies to microcontrollers: in most cases their IO pins can not tolerate voltage outside the ground-power interval (although some lower-voltage chip claim to be 5V tolerant). An exception was (is??) the RA4 pin on some Microchip uc's. But the 2003/2803 style driver chips are an excellent example of your second use case. \$\endgroup\$ Commented Jun 4, 2013 at 11:18
  • \$\begingroup\$ Between the MSP430's, Atmel AVRs, and Pic 16/18s, I have yet to see a modern microcontroller that can't sink or source the same amount of current. \$\endgroup\$
    – Passerby
    Commented Jun 4, 2013 at 18:48
  • \$\begingroup\$ m.Alin, Wouter_van_Ooijen, Passerby -- thanks for your comments, I have edited my answer. \$\endgroup\$
    – tcrosley
    Commented Jun 4, 2013 at 20:00
2
\$\begingroup\$

An open drain output is just an open-switch connected to 0V. To pass current through it you need to feed current into it and this can be done with a pull-up resistor. If you don't pass current into the pin you will not be able to see a voltage: -

enter image description here

Here are two devices sharing the same open-drain output - notice the pull-up resistor to +5V. In fact this circuit uses "open-drain" to perform logic - if either NAND gate is "activated" with 1,1 they will pull-down the BUS to 0V. Thus the logic delivered to the BUS is

INVERSE of BUS = A.B + C.D

MOSFETs are usually used as open-drain devices although regular BJTs can also perform this function. An open-drain output is a simplification of a regular CMOS output - it's quick at turning on down to ground but it will be slower on the return journey to +Logic because of the charge times of parasitic capacitors thru the pull-up resistor.

Open collector on wiki is a good read - it does the same as open drain and is mentioned in the article as is the little diagram shown above.

\$\endgroup\$
0
\$\begingroup\$

1) To simplify the first point in the answer by tcrosley, the advantage of not providing the pull-up resistor inside an output is in the ability to share that very pull-up resistor among many outputs. The outputs are then wired in parallel and all connected to the shared resistor and to ground.

2) The point “below” the resistor (in the schematics) is the place where the combined output is collected by other parts of the circuit. (Of course, it could all have been the other way around with respect to the ground and the supply.)

3) If you don't want to collect the combined output from many outputs (and the circuit uses the same voltage supply everywhere), then you don't want to use the outputs with no pull-up parts. Otherwise, you are provided with “incomplete” outputs (in a way), that you may customise to your needs.

\$\endgroup\$
1
  • \$\begingroup\$ I parsed your wall of text into numbered paragraphs. It makes it easier to understand when reading and commenting on certain parts or statements you made. Notice the paragraphs start at a change of context in your answer. \$\endgroup\$
    – user105652
    Commented Jun 26, 2016 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.