Expand Microcontroller Input Capacity Using Ternary Logic

Sept. 19, 2011
Using the analog converter input function of a compact microcontroller’s input pins to read ternary logic encoding allows two pins to sense as many as nine configuration states.

1 of Enlarge image
 

Using the analog converter input function of a compact microcontroller’s input pins to read ternary logic encoding allows two pins to sense as many as nine configuration states.

When designing with low pin-count microcontrollers, you sometimes need just one or two more digital input pins than you have available. Fortunately, many digital inputs on such microcontrollers also double as low-resolution analog converter inputs.

This analog capability provides an easy way to increase the number of logic states a microcontroller can read on its input pins, especially with relatively static states such as panel switch positions and jumper configurations. Simply use ternary (three-state) logic instead of binary.

Binary logic needs three input pins to sense up to eight encoded states, from (000)b to (111)b (23 – 1). With ternary logic, however, just two inputs will sense nine states from (00)t to (22)t (32 – 1).

The example in the figure shows an implementation with two ternary inputs, using two of four available analog inputs among the configurable I/O pins of a PIC12F675 microcontroller. The switches are single-pole double-throw (SPDT) type with a center off position and tap simple voltage dividers, presenting the input pins with 0, 2.5, or 5 V depending on switch position.

Software in the microcontroller reads and interprets these voltages as ternary values 0, 1, and 2. By combining the values from two inputs, the system obtains nine states for a configuration setup such as baud rate (see the table).

The technique could also be used with only with a single such panel switch and input, serving, for example, in a motor controller as an Up – Stop – Down control. Similarly, three switches and input pins could sense 27 states instead of needing four pins for 16 states in binary logic.

With ternary logic, then, you can increase the number of input states the microcontroller can sense while reducing the number of input pins needed.

About the Author

Dev Gualtieri

Dev Gualtieri received his PhD in solid-state science from Syracuse University in 1974. After many years doing research for a major aerospace company, he now does computer, electronic, and embedded-systems projects at his consulting company, Tikalon LLC (www.tikalon.com) in Ledgewood, N.J. He is the author of several books, available at Amazon. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!