Zibb

Design Idea

Three-state switch interface uses one microcontroller pin

A single microcontroller I/O pin senses the state of a three-position switch.

Kartik Joshi, Netaji Subhas Institute of Technology, New Delhi, India; Edited by Charles H Small and Fran Granville -- EDN, 2/21/2008

Human interfaces for electronic gadgets sometimes require three states for control. A single-axis joystick has states to define motions to the right, to the left, and with no motion. Similarly, a timer has control buttons that allow the timer to increment, decrement, and remain untouched. Engineers usually create these interfaces by using two independent pushbuttons, requiring two microcontroller pins. This Design Idea presents a way to sense three states of an SPDT (single-pole/double-throw) switch with a center-off state, using only a single pin of Atmel’s ATmega8 microcontroller (Reference 1 and Figure 1). Listing 1 is a simple program for the circuit.

The status of the pin of the microcontroller depends upon values of the DDR bit, the port bit, and its external connection. The microcontroller’s pin connects to ground using pulldown resistor R1 with resistance, typically, of a few hundred kilohms to impress the high-impedance state on the pin. You set the DDR register to zero. When the user toggles the switch to Position 1, the pin connects to VDD through resistor R5, and the pin bit is one, regardless of the value of the port bit. When the user toggles the switch to Position 3, the pin is grounded, and the pin bit is zero, regardless of the value of the port bit. In the center-off state, the pin bit follows the port bit. Table 1 summarizes the states of the pin for different values of the port and the external input.


Reference
  1. ATmega8/ATmega8L 8-bit AVR with 8K Bytes In-System Programmable Flash,” Atmel Corp, 2007.


Reed Business Information Resource Center

Featured Company


Related Resources

ADVERTISEMENT

ADVERTISEMENT

Related Content

 

By This Author

There are no additional articles written by this author.


ADVERTISEMENT

Knowledge Center


Events

Microchip Worldwide Embedded Designer’s Forum
Dates: 10/6/2009 - 2/15/2010
Location: 120 Locations Worldwide

Microprocessor Test and Verification (MTV'09)
Dates: 12/7/2009 - 12/8/2009
Location: Austin, TX

Oxford University Practical RF/Microwave Design Short Course
Dates: 1/18/2010 - 1/22/2010
Location: Oxford, United Kingdom

Oxford University Digital Signal Processing Short Course
Dates: 1/25/2010 - 1/27/2010
Location: Oxford, United Kingdom

Oxford University Digital Signal Processing Implementation Short Course
Dates: 1/28/2010 - 1/28/2010
Location: Oxford, United Kingdom

Submit an EventSubmit an Event




Technology Quick Links

EDN Marketplace


©1997-2009 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other Reed Business sites