12-bit AD converter Since everything in the microcontroller world is represented with "0's" and "1's", how do we cater for a signal that is 0.5 or 0.77? Most of the world outside a computer consists of audio signals. Apart from speech and music, there are many quantities that need to be fed into a computer. Humidity, temperature, air pressure, colour, turbidity, and methane levels, are just a few. The answer is to take a number of digital lines and combine them so they can "read" an analogue value. An analogue value is any value between 0 and 1. You can also call it a "fractional value." All the above quantities must now be converted to a value between 0 and 1 so they can be fed into a computer. This is the broad concept. It becomes a little more complex in application. If we take 8 lines and arrange than so they accept binary values, the total count will be 256 (this is obtained by a count to 255 plus the value 0). If we connect these 8 lines into a "black box," they will be called output lines and so we must provide a single input line. With this arrangement we can detect up to 255 increments between zero and "1." This black box is called a CONVERTER and since we are converting from Analogue to Digital, the converter is called an A-to-D converter or AD CONVERTER. AD converters can be classified according to different parameters. The most important parameters are precision and mode of transferring data. As to precision, the range is: 8-bit, 10-bit, 12-bit, 14-bit, 16-bit. Since 12-bit conversion is an industrial standard, the example we have provided below was done with a 12-bit AD converter. The other important parameter is the way data is transferred to a microcontroller. It can be parallel or serial. Parallel transmission is faster. However, these converters are usually more expensive. Serial transmission is slower, but in terms of cost and fewer input lines to a microcontroller, it is the favourite for many applications. Analogue signals can sometimes go above the allowed input limit of an AD converter. This may damage the converter. To protect the input, two diodes are connected as shown in the diagram. This will protect from voltages above 5v and below 0v. In our example we used a LTC1286 12-bit AD converter (Linear Technology). The converter is connected to the microcontroller via three lines: data, clock and CS (Chip Select). The CS line is used to select an input device as it is possible to connect other input devices (eg: input shift register, output shift register, serial AD converter) to the microcontroller and have them use the same data lines. The circuit below shows how to connect an AD converter, reference and LCD display to a micro. The LCD display has been added to show the result of the AD conversion. Connecting an AD converter with voltage reference to a microcontroller The Macro used in this example is LTC86 and is found in LTC1286.inc file. The LTC86 Macro has three arguments: LTC86 macro Var_LO, Var_HT, Var Var_LO variable is where the result of lower byte conversion is stored Var_HI variable is where the result of higher byte conversion is stored Var loop counter Example: LTC86 LO, HI, Count The four bits of the highest value are in variable HI, and first eight bits of conversion result are in variable LO. Count is an assistant variable to count the passes through loops. The following example shows how macros are used in the program. The program reads the value from an AD converter and displays it on the LCD display. The result is given in quantum's. Eg: for 0V the result is 0, and for 5V it is 4095.