As a hobbyist, I’m inclined to find some cool piece of hardware, buy it, and then try and figure out what it’s good for later. True once again with my Analog to Digital (A2D) board. It just has to be useful – its so much fun to play with. Over the years, it has collected a lot of dust. Well, I’m happy to say that Home Automation gives the old A2D board a lot more justification to exist on your workbench. First, lets take a look at an A2D board, and then we can see what you can do with it.
An A2D board does exactly what its name implies. It converts an analog voltage to a digital value that a computer can read. Anything that produces a varying voltage can supply the input: a temperature or pressure sensor, a potentiometer, a stress gauge, or the output of a photo-resister. Whatever the input, the A2D generates a numerical representation that is proportional to the input voltage.
An A2D board has several important characteristics; the Analog Input, the Digital Output, and the conversion process. An A2D converter’s analog inputs can extend over virtually any voltage range. Typical commercial devices restrict the inputs to between 0 and 5 volts. Most A2D boards will not accept negative inputs, but some will let you set the upper and lower limits. In these cases, you normally must change the limits for all available inputs (not each input individually), and you may be restricted to changing the upper and lower limits by equal but opposite amounts.
The output from an A2D is a number between 0 and some upper limit. The upper limit is determined by the number of bits present in the converter’s digital output. For an 8-bit converter, this is 255 (the largest number you can represent in 8 bits). For 12-bit and 16-bit converters it is 4096 and 65536, respectively. More bits give you better resolution. For example, if your input range is 0 to 5 volts and you have an 8-bit output, each step of the output (0 to 1, 1 to 2, 2 to 3, etc.) represents 0.0195 volts. If the input varies by less than that, the digital output remains the same. For the same input range a 12-bit device’s step represents 0.00122 volts. A much smaller change in input will be reflected in the digital output. Generally speaking, the more bits the better, but the cost of the A2D board goes up sharply when you go above 8-bits on output. For this reason 8 bit devices remain very popular for the hobbyist.
Conversion between the analog and digital domain is performed by a number of different processes. One commonly available, low cost converter is the ADC0808 by National Semiconductor. A block diagram of of the ADC0808 is shown.
ADC0808 Block Diagram
It uses a 256 step resistor ladder in conjunction with a transistorized switch tree and a comparator to determine the best match. The switch tree selects one of the 256 voltages represented in the resistor ladder, while the comparator compares this voltage with the input voltage. Each voltage represented in the resistor ladder is compared to the input until the best match is found. When the conversion completes, the closest matching level represents the digital output and is placed in the latch buffer.
One difficulty with any A2D board is recognizing when to read the inputs. Although most A2D boards will generate an interrupt, this signal is used to indicate conversion completion and not an input change. You must signal the A2D board when you want to convert the input. This can be done based on time or by using another input, such as a digital input, as a signal to check the A2D board’s interface.
Putting Your A2D to Work
Okay, so just what can you do with an A2D board? Temperature sensors, level sensors, analog switches, noise sensors, frequency discriminators, flex sensors, pressure sensors, light sensors, in short, just about anything you can measure over a range.
One neat thing you can do with an A2D board is build a control panel with a bunch of switches for inputs without having to tie up a lot of expensive digital inputs. A sixteen switch panel is easy to build, requires only a single A2D analog input and one digital input for notification.
Switch Wiring Diagram
The diagram to the right shows 5 switches for simplicity. You can actually use just about any number up to about 50 or so (you need enough difference between inputs to tell them apart). The 1k resistors create a voltage ladder by dividing the 5 volt supply by the number of steps. With 5 switches, each step is one volt. Closing switch 2 results in a 4 volt signal level. Closing switch 5 results in 1 volt.
Remembering that each step represents 0.0195 volts, we can compute the digital value for each input. One volt is converted to a digital value of 51 (decimal), two volts is converted to 102, and so on. Program your automation system so that an A2D input greater than 25 but less than 75 performs one set of instructions, a value greater than 75 but less than 150 performs another set, and so on down the line. Adjust your ranges to reflect the number of switches you choose to use.
Double pole switches allow using one pole for the analog signal, while the other is tied to a digital input to notify the system of a change of state in the analog switch. You can also use a set of momentary contact, three position toggle switches with good effect (left for mode on, right for mode off, for example). In this case use two digital inputs driven from the second pole to recognize which way the switch is moved and tie both poles of the analog side from the resistor ladder to the signal line. Another variation is to use a potentiometer instead of switches. A linear one turn device works best. This lets you set any value and can be useful to control a set of X10 lamps without having to hold a button to set a dim value. Just turn the knob and press the “Set” button. You can also add an LED and use a digital output to acknowledge requests if you like..
So far we have taken a general look at how an A2D works, and presented a simple but useful example in building an analog based switch. In the next issue we will take a look at attaching temperature sensors and the related subjects of signal conditioning and digital resolution.