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.

Sponsored Recommendations

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

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