Professional Documents
Culture Documents
General purpose input/output (GPIO) pins on microcontrollers have various modes for both input and output.
Input modes may include pullup or pulldown resistors, hysteresis, or some combination. Output modes can be
pushpull, highdrive or opendrain.
Input Modes
GPIO input modes typically include high impedance, pullup, pulldown and repeater. Most input circuitry feature
hysteresis which prevents spurious state changes.
Pull Up/Down
If an input is configured with an internal pullup, it will be high unless it is externally driven low. The converse is
true with pulldown inputs (learn more about pulling resistors). Some GPIO pins also support changing the pull
up and pulldown settings dynamically using repeater mode.
Repeater
When a GPIO is configured in repeater mode, the pullup is enabled when the pin is driven high, and the pull
down is enabled when the pin is driven low. If nothing is driving the pin, the pullenable will retain its last known
state. In some designs, this can prevent power from leaking on pins in an indeterminate state.
Hysteresis
http://stratifylabs.co/embedded%20design%20tips/2013/10/21/TipsUnderstandingMicrocontrollerPinInputOutputModes/ 1/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes
Virtually all GPIO inputs use a principle called hysteresis to prevent spurious changes in state when an input
value changes. “Hysteresis is the dependence of a system on not only its current environment but also on its
past” (read more). Hysteresis is implemented on GPIO by setting two thresholds for a digital input which are VIH
and VIL typically enumerated in the “Electrical Characteristics” section of microcontroller datasheets. VIH is the
inputhigh voltage and represents the minimum voltage that must be applied to drive the pin high. VIL is the
maximum inputlow voltage needed to drive the pin low. This means if the input voltage is greater than VIL and
less than VIH, the value at the pin depends on whether the past input value was above VIH, in which case the
pin is high, or below VIL, which means the pin is low. The following graph illustrates the difference between no
hysteresis (A) and hysteresis (B) for a given signal (U).
Output Modes
PushPull
A pushpull output has the ability to both source and sink current. TTL and CMOS logic circuits use pushpull
outputs. A CMOS pushpull topology is illustrated in the figure below. The “C” in CMOS stands for
complementary because M2 and M3 are complementary devices. M2 is a PMOS device while M3 is an NMOS
device. Because M2 and M3 have the same input signal, M3 is on whenever M2 is off and vice versa. An open
drain output is also shown in the figure at the top of the page.
OpenDrain
From the figure above, the namesake of “opendrain” is obvious to anyone who is familiar with MOSFETs. A
MOSFET has three terminals called: gate, source, and drain. In an opendrain configuration, the source is
grounded, the gate is driven internally, and the drain is open (i.e. not connected to anything).
An opendrain output can only sink current. Its two states are low and highimpedance. When M1 is on, the
output is set to 0V. When M1 is off, the output is not driven high nor low. Most applications, including I2C buses,
use an external pullup resistor on any opendrain outputs. Another useful application for opendrain outputs is
having multiple external devices drive a single, activelow interrupt pin on a microcontroller.
High Drive
http://stratifylabs.co/embedded%20design%20tips/2013/10/21/TipsUnderstandingMicrocontrollerPinInputOutputModes/ 2/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes
High drive pins are pushpull pins that are capable of higher current.
A typical pushpull output is able to source/sink around +/8ma where a high drive output can source up to
+/40ma. The electrical characteristics specified in the datasheet enumerate the current capacity of each pin.
Understanding the current capabilities of pins is important to reducing circuit board costs and complexity. If a
microcontroller is capable of directly driving a motor or LED, there is no need to add external circuitry (such as a
MOSFET).
Conclusion
GPIO is the simplest IO available on microcontrollers. However, it is important to understand the intricacies of
GPIO such as the input and output modes. Understanding the capabilites of the GPIO can save cost and
complexity in an embedded design while boosting flexiblity.
(/embedded%20design%20tips/2013/10/19/TipsSensingtheSourceCurrentinanEmbeddedApplication/)
(/archive) (/categories/)
(/embedded%20design%20tips/2013/10/22/TipsUSBVirtualSerialPortFirmware/)
Embedded C Tutorial
Hello World (/embedded%20c%20tutorial/2013/12/01/EmbeddedCTutorialHelloWorld/)
Functions (/embedded%20c%20tutorial/2013/12/02/EmbeddedCTutorialFunctions/)
http://stratifylabs.co/embedded%20design%20tips/2013/10/21/TipsUnderstandingMicrocontrollerPinInputOutputModes/ 4/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes
Operators (/embedded%20c%20tutorial/2013/12/04/EmbeddedCTutorialOperators/)
http://stratifylabs.co/embedded%20design%20tips/2013/10/21/TipsUnderstandingMicrocontrollerPinInputOutputModes/ 5/5