You are on page 1of 5

11/08/2016 Understanding Microcontroller Pin Input/Output Modes

Understanding Microcontroller Pin


Input/Output Modes Embedded Design

General purpose input/output (GPIO) pins on microcontrollers have various modes for both input and output.
Input modes may include pull­up or pull­down resistors, hysteresis, or some combination. Output modes can be
push­pull, high­drive or open­drain.

Input Modes
GPIO input modes typically include high impedance, pull­up, pull­down and repeater. Most input circuitry feature
hysteresis which prevents spurious state changes.

Floating, High Impedance, Tri­Stated


When an input pin is in high impedance input mode, its state is indeterminate unless it is driven high or low by
an external source. Pins configured as high impedance inputs and not currently driven are called “floating”.
Many times “float” or “floating” is used interchaneably with “high impedance” or “tri­stated”. To prevent pins from
floating when they are not externally driven, internally pulling resistors are used.

Pull Up/Down
If an input is configured with an internal pull­up, it will be high unless it is externally driven low. The converse is
true with pull­down inputs (learn more about pulling resistors). Some GPIO pins also support changing the pull­
up and pull­down settings dynamically using repeater mode.

Repeater
When a GPIO is configured in repeater mode, the pull­up 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 pull­enable 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/Tips­Understanding­Microcontroller­Pin­Input­Output­Modes/ 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
input­high voltage and represents the minimum voltage that must be applied to drive the pin high. VIL is the
maximum input­low 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).

Image from Wikipedia: Schmitt Trigger

Output Modes
Push­Pull
A push­pull output has the ability to both source and sink current. TTL and CMOS logic circuits use push­pull
outputs. A CMOS push­pull 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.

Open­Drain
From the figure above, the namesake of “open­drain” is obvious to anyone who is familiar with MOSFETs. A
MOSFET has three terminals called: gate, source, and drain. In an open­drain configuration, the source is
grounded, the gate is driven internally, and the drain is open (i.e. not connected to anything).

An open­drain output can only sink current. Its two states are low and high­impedance. 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 pull­up resistor on any open­drain outputs. Another useful application for open­drain outputs is
having multiple external devices drive a single, active­low interrupt pin on a microcontroller.

High Drive

http://stratifylabs.co/embedded%20design%20tips/2013/10/21/Tips­Understanding­Microcontroller­Pin­Input­Output­Modes/ 2/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes

High drive pins are push­pull pins that are capable of higher current.
A typical push­pull 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 32 (/tags#embedded­ref) microcontroller 7 (/tags#microcontroller­ref)

gpio 3 (/tags#gpio­ref) programming 9 (/tags#programming­ref)

 (/embedded%20design%20tips/2013/10/19/Tips­Sensing­the­Source­Current­in­an­Embedded­Application/)

 (/archive)  (/categories/)

 (/embedded%20design%20tips/2013/10/22/Tips­USB­Virtual­Serial­Port­Firmware/)

Embedded Design Tips


8 vs 16 vs 32 Bit Microcontrollers­­A Case Study (/embedded%20design%20tips/2013/10/01/Tips­8­vs­16­
vs­32­Bit­Microcontrollers/)

A FIFO Buffer Implementation (/embedded%20design%20tips/2013/10/02/Tips­A­FIFO­Buffer­


Implementation/)

ADC Thermistor Circuit and Lookup Table (/embedded%20design%20tips/2013/10/03/Tips­ADC­


Thermistor­Circuit­and­Lookup­Table/)

An Easy­to­Use Digital Filter (/embedded%20design%20tips/2013/10/04/Tips­An­Easy­to­Use­Digital­


Filter/)

Building and Installing Autotools (/embedded%20design%20tips/2013/10/08/Tips­Building­and­Installing­


Autotools/)

Context Switching on the Cortex­M3 (/embedded%20design%20tips/2013/10/09/Tips­Context­Switching­


on­the­Cortex­M3/)

Decoupling Capacitors (and Other Power Rules of Thumb)


(/embedded%20design%20tips/2013/10/10/Tips­Decoupling­Capacitors/)

Effective Use of ARM Cortex­M3 SVCall (/embedded%20design%20tips/2013/10/12/Tips­Effective­Use­of­


ARM­Cortex­M3­SVCall/)
http://stratifylabs.co/embedded%20design%20tips/2013/10/21/Tips­Understanding­Microcontroller­Pin­Input­Output­Modes/ 3/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes

FFT on the ARM Cortex M3 (/embedded%20design%20tips/2013/10/13/Tips­FFT­on­the­ARM­Cortex­M3/)

How Microcontrollers Work (/embedded%20design%20tips/2013/10/14/Tips­How­Microcontrollers­Work/)

Motor Control using PWM and PID (/embedded%20design%20tips/2013/10/15/Tips­Motor­Control­using­


PWM­and­PID/)

RAM/Flash Usage in Embedded C Programs (/embedded%20design%20tips/2013/10/18/Tips­RAM­Flash­


Usage­in­Embedded­C­Programs/)

Sensing the Source Current in an Embedded Application (/embedded%20design%20tips/2013/10/19/Tips­


Sensing­the­Source­Current­in­an­Embedded­Application/)

Understanding Microcontroller Pin Input/Output Modes (/embedded%20design%20tips/2013/10/21/Tips­


Understanding­Microcontroller­Pin­Input­Output­Modes/)

USB Virtual Serial Port Firmware (/embedded%20design%20tips/2013/10/22/Tips­USB­Virtual­Serial­Port­


Firmware/)

Using Doxygen with C (/embedded%20design%20tips/2013/10/23/Tips­Using­Doxygen­with­C/)

Using LEDs in Embedded Designs (/embedded%20design%20tips/2013/10/24/Tips­Using­LEDs­in­


Embedded­Designs/)

Using Pull­Up and Pull­Down Resistors (/embedded%20design%20tips/2013/10/25/Tips­Using­Pull­Up­


and­Pull­Down­Resistors/)

Controlling a Solenoid (/embedded%20design%20tips/2013/10/26/Tips­Controlling­a­Solenoid/)

Using Op Amps in Embedded Design (/embedded%20design%20tips/2013/10/27/Tips­Using­Op­Amps­in­


Embedded­Design/)

Integrating Doxygen and Bootstrap (/embedded%20design%20tips/2014/01/07/Tips­Integrating­Doxygen­


and­Bootstrap/)

Applications without an MMU (/embedded%20design%20tips/2014/05/03/Applications­without­MMU/)

Building and Installing a Cortex­M Compiler on Mac, Windows or Linux


(/embedded%20design%20tips/2016/03/13/Tips­Building­and­Installing­a­Cortex­M­Compiler/)

Embedded C Tutorial
Hello World (/embedded%20c%20tutorial/2013/12/01/Embedded­C­Tutorial­Hello­World/)

Functions (/embedded%20c%20tutorial/2013/12/02/Embedded­C­Tutorial­Functions/)

Raw Types (/embedded%20c%20tutorial/2013/12/03/Embedded­C­Tutorial­Raw­Types/)

http://stratifylabs.co/embedded%20design%20tips/2013/10/21/Tips­Understanding­Microcontroller­Pin­Input­Output­Modes/ 4/5
11/08/2016 Understanding Microcontroller Pin Input/Output Modes

Operators (/embedded%20c%20tutorial/2013/12/04/Embedded­C­Tutorial­Operators/)

Flow Control (/embedded%20c%20tutorial/2013/12/05/Embedded­C­Tutorial­Flow­Control/)

Pointers and Arrays (/embedded%20c%20tutorial/2013/12/07/Embedded­C­Tutorial­Pointers­and­Arrays/)

Preprocessor Directives (/embedded%20c%20tutorial/2013/12/08/Embedded­C­Tutorial­Preprocessor/)

Compound Data Types (/embedded%20c%20tutorial/2013/12/09/Embedded­C­Tutorial­Compound­Data­


Types/)

Keywords Reference (/embedded%20c%20tutorial/2013/12/10/Embedded­C­Tutorial­Keyword­Reference/)

Order of Operations Reference (/embedded%20c%20tutorial/2013/12/11/Embedded­C­Tutorial­Order­of­


Operations/)

© 2016 Stratify Labs, Inc

http://stratifylabs.co/embedded%20design%20tips/2013/10/21/Tips­Understanding­Microcontroller­Pin­Input­Output­Modes/ 5/5

You might also like