This content requires the Adobe Flash Player and a browser with JavaScript enabled. Click here to get the latest version of Adobe Flash Player.

Three-state switch interface uses one microcontroller pin

Kartik Joshi, Netaji Subhas Institute of Technology, New Delhi, India -- EDN Europe, 01 Apr 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 centeroff state, using only a single pin of Atmel’s (www.atmel.com) ATmega8 microcontroller (Reference 1 and Figure 1).

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.

REFERENCES
  1. “ATmega8/ATmega8L 8-bit AVR with 8K Bytes In-System Programmable Flash,” Atmel Corp, 2007, www.atmel.com/dyn/resources/prod_documents/2486S.pdf.

 

Our Sponsors



Ads by Google