Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8588
Скачиваний: 0
544 |
Chapter 16 |
3 2 1 0 <= bits
Binary output
+5V |
A/D |
|||||||||||||
Analog |
||||||||||||||
Converter |
||||||||||||||
input |
||||||||||||||
Figure 16-1 A/D Converter Block Diagram
16.0 A/D Converters
In electronics, the typical A/D or ADC converter is a device that takes a voltage input and returns a binary digital number. Figure 16-1 is a block diagram of an A/D converter.
The electronic A/C converter requires an input in the form of an electrical voltage. Non-electric quantities must be changed into a voltage level before the conversion can be performed. The device that performs this conversion is called a transducer. For example, a digital barometer must be equipped with a transducer that converts the measurement into voltage levels. The voltage levels can then be fed into an A/D converter and the result output in digital form.
16.0.1 Converter Resolution
An ideal A/D converter outputs into an infinite number of discrete steps that exactly represent the analog quantity. Needless to say, such a device cannot exist, and a real A/D converter must be limited to a numeric range. For example, the device in Figure 16-1 outputs a voltage range of 0 to +5 volts in four binary digits that represent values between 0 and 15. Another A/D converter may produce output in eight binary digits, and another in sixteen binary digits. The number of discrete values in the conversion is called the resolution. The converter’s resolution is usually expressed in bits. Figure 16-2 represents an A/C converter with a voltage range of 0 to +5 volts and a resolution of three bits.
Suppose that a value of 2.5 volts were input into the A/D converter in Figure 16-2. Since the output has a resolution in the range 0 to 7, the converter’s output would be either 4 or 5. The non-linear characteristic of the output determines a quantization error that increases as the converter resolution decreases. Converters used in PIC circuits have a resolution of either 8, 10, or 12 bits. In each case the output range, or quantization level, is 0 to 255, 0 to 1023, or 0 to 4095. The voltage resolution of the converter is its maximum voltage range divided by the number of quantization levels. A device with a voltage range of 5 volts and a range of 255 levels has a voltage resolution of:
Analog to Digital and Realtime Clocks |
545 |
+5
V o
l 2.5 t
s
0
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Binary output
Figure 16-2 Converter Quantization Error
voltage resolution = 5 = 0.01960 volts = 19.60mV
255
16.0.2 ADC Implementation
The analog-to-digital converter performs accurately only if the input voltage is within the converter’s valid range. This range is usually selected by setting high and low voltage references on converter pins. For example, if +4 volts is input into the converter’s positive reference pin and +2 volts into the negative reference pin, then the converter’s voltage range lies between these values. In many PIC applications the converter range is selected as the system’s supply voltage and ground, that is, +5 and 0 volts. When a different range is externally referenced, there is a general restriction that the range cannot exceed the system’s positive and negative limits (Vdd and Vss). Also, a minimum difference is required between the high and low voltage references.
The output of the ADC is a digital representation of the original analog signal. In this context, the term quantization refers to subdividing a range into small but measurable increments. The quantization process can introduce a quantization error, which is similar to a rounding error.
The time required for the holding capacitor on the ADC to charge is called the acquisition time. The holding capacitor on the ADC must be given sufficient time to settle to the analog input voltage level before the actual conversion is initiated. Otherwise, the conversion is not accurate. The acquisition time is determined by the impedance of the internal multiplexer and that of the analog source. The exact acquisition time can be determined from the device’s data sheet, although 10K ohms is the maximum recommended source impedance for 8- and 10-bit converters and 2.5K ohms for 12-bit converters.
548 |
Chapter 16 |
Port-B, line 0 as input since this is the one connected to the DO line. The remaining lines in ports A and B are defined as output. ADC0831 processing consists of a single procedure that reads the analog line and returns an 8-bit digital value. The processing required is performed in the following steps:
1.The data return register (named rcvdata) is cleared and the bit counter register is initialized to count 8 bits.
2.The ADC0831 is prepared by bringing the CS line low and pulsing the CLK line.
3.The CLK line is pulsed and one bit is read from the low-order bit (DO line) of Port-B.
4.The bit is shifted into the data return register and the bit counter is decremented.
5.If the bit counter is exhausted, execution ends and the ADC is turned off. Otherwise processing continues at step 3.
The following procedure, from the ADF84 program, reads digital data from the ADC0831:
;============================
;procedure to read and
;convert analog line ;============================
;ON ENTRY:
;Code assumes that the ADC0831 DO line is initialized for
;input, while CLK and CS lines are output
;From ADC0831 wiring diagram. All lines in Port-B
; |
DO |
= |
RB0 |
==> INPUT |
|
; |
CLK |
= |
RB1 |
<== |
OUTPUT |
; |
CS |
= |
RB2 |
<== |
OUTPUT |
;ON EXIT:
;Returns 8-bit digital value in the register rcvdata
ana2dig:
;Clear data register and init counter for 8 bits
clrf |
rcvdata ; Clear register |
||
movlw |
0x08 |
; Initialize counter |
|
movwf |
bitCount |
||
; Prepare to read analog line |
|||
bcf |
PORTB,CS ; CS pin low to enable ADC |
||
nop |
; Delay for 4MHz clock |
||
bsf |
PORTB,CLK |
; Set CLK high |
|
Nop |
|||
bcf |
PORTB,CLK ; Reset CLK to start conversion |
||
nop |
|||
nextB: |
|||
; Pulse CLK line to read bit from ADC |
|||
bsf |
PORTB,CLK |
; CLK high |
|
nop |
bcf |
PORTB,CLK |
; CLK low |
Nop |
|||
; Read analog line and store data, bit by bit