Path: EDN Asia >> Design Ideas >> IC/Board/Systems Design >> Three-state switch interface employs one MCU pin
IC/Board/Systems Design Share print

Three-state switch interface employs one MCU pin

08 Apr 2016  | Kartik Joshi

Share this page with your friends

Human interfaces for electronic gadgets sometimes need 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 single-pole/double-throw (SPDT) switch with a centre-off state, using only a single pin of Atmel's ATmega8 microcontroller (Reference 1 and figure).


Figure: Using only one I/O pin, this circuit and a simple program can sense the state of a three-position switch.


Table: Using only one I/O pin, this circuit and a simple program can sense the state of a three-position switch.


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 centre-off state, the pin bit follows the port bit. The table summarises the states of the pin for different values of the port and the external input.


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


About the author
Kartik Joshi contributed this article.


This article is a Design Idea selected for re-publication by the editors. It was first published on March 6, 2008 in EDN.com.




Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.


Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming


News | Products | Design Features | Regional Roundup | Tech Impact