Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
The PIC Microcontroller Book for beginning (Nebojsa Matic).pdf
Скачиваний:
229
Добавлен:
12.08.2013
Размер:
2.46 Mб
Скачать

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

12-bit Analog to Digital 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 analogue 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 "0" 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 ADC.

AD converters can be classified according to different parameters. The most important parameters are precision and mode of data transfer. As to precision, the range is: 8-bit, 10bit, 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 ADC. 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 ADC. 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 ADC (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 ADC) to the same lines of the microcontroller.

The circuit below shows how to connect an ADC, reference and LCD display to a micro. The LCD display has been added to show the result of the AD conversion.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (1 of 6) [4/2/2003 16:19:11]

Chapter 6 - Samples

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.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (2 of 6) [4/2/2003 16:19:11]

Chapter 6 - Samples

The LTC86 Macro has three arguments:

LTC86 macro Var_LO, Var_HI, 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 ADC and displays it on the LCD display. The result is given in quantums. Eg: for 0V the

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (3 of 6) [4/2/2003 16:19:11]

Chapter 6 - Samples

result is 0, and for 5V it is 4095.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (4 of 6) [4/2/2003 16:19:11]

Chapter 6 - Samples

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (5 of 6) [4/2/2003 16:19:11]

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_11Poglavlje.htm (6 of 6) [4/2/2003 16:19:11]