You are on page 1of 17

Analog-to-digital converter (ADC )

Need to have some means to convert them into digital signal so


that computers can handle
Analog-to-digital converter (ADC) is a device which can convert
analogue voltage to digital numbers so that microcontrollers can
handle and process the data.
ADC are the most widely used devices for data acquisition
ADC has n-bit resolution, where n can be 8, 12, 16 or even 24 bits.
The higher-resolution ADC provides a smaller step size.
Step size is the smallest change that can be recognized by ADC.
Analog-to-digital converter (ADC )
An ADC has a resolution of 8 bits, the range is divided into 2^8=256 steps
(from 0 – 255). But there are 255 quantization levels.

Vcc
Step Size  n
2 1
Vcc is the reference voltage of ADC with n-bit resolution
Table 10.3 : Resolution versus Step Size for ADC (if Vcc =
5V)
n-bit Number of steps Step Size (mV)
8 2^8 = 256 5/255 = 19.61
10 2^10 = 1024 5/1023 = 4.89
12 2^12 = 4096 5/4095 = 1.22
16 2^16 = 65536 5/65535 = 0.076
ADC0804 Chip (Free Running Mode)
+5V
20
10k 6 Vin(+) 18
POT D0 Port of
7 Vin() 17
8 A GND
D1 8-bit uC
D2 16
9 15
Vref/2
D3 To
14
19 D4 LEDs
CLK R 13
D5
10k 4 D6 12
CLK in 11
150 pF ADC08 D7
1 04
CS
2 WR 3
RD
10 5 Normally
D GND INTR
open
START
Figure 10.1
ADC0804 Chip
CS
Active low input used to activate the ADC0804 chip.

RD (data enable)
Active low input used to get converted data out of the ADC0804 chip.
When CS = 0, if a high-to-low pulse is applied to the RD pin, the 8-bit
digital output shows up at the D0-D7 data pins.

WR (start conversion)
Active low input used to inform the ADC0804 to start the conversion
process. If CS = 0 when WR makes a low-to-high transition, the
ADC0804 starts converting the analog input value of Vin to an 8-bit
digital number. When the data conversion is complete, the INTR pin is
forced low by the ADC0804.
ADC0804 Chip
CLK IN and CLK R
Connect to external capacitor and resistor for self-clocking, f = 1/(1.1RC).
The clock affect the conversion time and this time cannot be faster than
110s.

INTR (end of conversion)


This is an active low output pin. When the conversion is finished, it goes
low to signal the CPU that the converted data is ready to be picked up.
After INTR goes low, we make CS = 0 and send a high-to-low pulse to the
RD pin to get the data out of the ADC0804 chip.

Vin (+) and Vin ()


These are the differential analog inputs where Vin = Vin (+)  Vin ().
Often the Vin () pin is connected to ground and the Vin (+) pin is used as
the analog input to be converted to digital.
VREF
2
ADC0804 Chip V
step size  8 2  REF
2 1 255
VCC
This is the +5V power supply. It is also used as a reference voltage
when the Vref/2 (pin 9) input is open.

Vref/2
Input voltage pin used for the reference voltage. If this pin is open, the
analog input voltage for the the ADC is ranged from 0 to 5 volts.

Vref/2 (V) Vin (V) Step Size (mV)


Not connected 0 to 5 5/255 = 19.60
ADC0804 has
resolution of 2.0 0 to 4 4/255 = 15.69
8 bits 1.5 0 to 3 3/255 = 11.76
1.28 0 to 2.56 2.56/255 = 10.04
1.0 0 to 2 2/255 = 7.84
0.5 0 to 1 1/255 = 3.92
Pin Vref/2 is open, Step size =19.6mV
ADC0804 Chip
D0 – D7
D0 – D7 are the digital data output pins. These are the tri-state
buffered and the converted data is accessed only when CS = 0
and RD is forced low. The output voltage:

Vin
Dout 
Step size

Analog Ground and Digital Ground


Analog ground is connected to the ground of the analog signal
while digital ground is connected to the ground of the Vcc pin.
Question: An analog input voltage of 3.5V, Pin Vref/2 is open.
Solution:
Dout = 3.5V / 19.6mV = 178 or 179 (depends on accuracy of ADC)
Signal control on ADC0804

1. Make CS = 0 and send a L-to-H pulse to pin WR to start the


conversion.
2. Keep monitoring the INTR pin. If INTR is low, the conversion is
finished and we can go to the next step. If INTR is high, keep
polling until it goes low.
3. After the INTR has become low, we make CS = 0 and send a H-
to-L pulse to the RD pin to get the data out of the ADC0804 IC
chip.
Testing the ADC0804

8051 ADC0804 +5V

P2.5 RD VCC
P2.6 WR CLK R
CLK IN
P1.0 D0
: 10k
Vin(+)
: POT
Vin()
:
:
A GND
: Vref/2
P1.7 D7 D GND

P2.7 INTR CS
Example 10-1
Write a program to monitor the INTR pin and bring the digital input value into register A.
Then call a subroutine to display the input value on a 7-segment display. Do this
continuously.

;P2.6 = WR (Start conversion needs a L-to-H pulse)


; P2.7 = INTR (When low, end-of-conversion)
; P2.5 = RD (H-to-L will read the data from ADC chip)
; P1.0 – P1.7 = D0 – D7 of the ADC0804
;
MOV P1, #0FFH ; make P1=input
BACK: CLR P2.6 ; WR=0
SETB P2.6 ; WR=1 L-to-H to start conversion
HERE: JB P2.7, HERE ; wait for end of conversion
CLR P2.5 ; conversion finished, enable RD
MOV A, P1 ; read the data
ACALL DATA_DISPLAY ; display the data
SETB P2.5 ; make RD=1 for next round
SJMP BACK
Referred to Example 10.1, the digital values output from the ADC0804
correspond to the analogue voltage inputs. It is calculated by:

V 5 5 Vin
Step Size  n cc Step Size  8   0.019608 V Dout 
2 1 2  1 255 Step size

Analogue input voltage Digital Value Output


Vin (V) Dout
0 0/0.019608 = 0
0.5 0.5/0.019608 = 26
1.0 1.0/0.019608 = 51
1.5 1.5/0.019608 = 77
2.0 2.0/0.019608 = 102
5.0 5.0/0.019608 = 255
Example of ADC Application
Temperature detection
A temperature sensor (LM34 or LM35) is interfaced to the 8051
via an ADC (ADC0804)
The output voltage from the LM34/LM35 is linearly proportional
to the measuring temperature
The ADC0804 converts the output voltages from the
LM34/LM35 into digital signals, which correspond to the
measured temperature.
They are then handled by the 8051
Digital-to-Analog (DAC) Conversion
The digital-to-analog converter (DAC) is a device widely used to convert
digital values to analog signals.
It does the reverse operation of an ADC
The resolution of DAC depends on the no. of binary bits input to it.
The common ones are 8, 10 and 12 bits.
An 8-input DAC provides 256 discrete voltages (or current) levels of output.
(The 12-bit DAC gives 4096 discrete levels).

D0
Analog output
Digital (Voltage or current)
inputs DAC

D7 Figure 10.5
DAC0808 Chip (MC1408)
+5V Vref (e.g +5V)

VCC Rref1
P2.5
P2.6 Vin(+) Iref = Vref/(Rref1+Rref2)
= 2mA (Typical)
Iref Rref 2
P1.0 D0 Vin() R0

DAC0808 Iout
8051  To Scope
Comp. + Vout = 0 to 10V

P1.7 D7 Vee
 15V
GND

Figure 10.6
DAC0808 Chip (MC1408)
Operating Principle
• In the DAC0808, the digital inputs are converted to corresponding current (I out).
• Then by connecting a resistor to the Iout pin, the current will further convert to

voltage level.
• The total current provided by the output Iout pin is a function of the reference

current (Iref) and is follows:

 D7 D6 D5 D 4 D3 D2 D1 D0 
I out  I ref         
 2 4 8 16 32 64 128 256 
Converting Iout to voltage (Vout)
Connect the output pin Iout to a output standard resistor and hence convert
this current to a voltage.
Output voltage, Vout = Iout x Ro
Example
Assume that Ro = 5k, Rref1 = 1k , Rref2 = 1.5k  and using a standard 5V
supply connected to Vref(+), calculate Vout for the following binary inputs.
(a) 1001 1001 (99H) (b) 1100 1000 (C8H)

Solution: 5
I ref   2mA
1000  1500

(a) 99H = 15310 153


I out  ( 2mA)  1.195mA
256
Vout  (1.195mA)(5000k)  5.975V

(b) C8H = 20010 200


I out  ( 2mA)  1.562mA
256
Vout  (1.562mA)(5000k)  7.8125V
Example
In order to generate a star-step ramp, set up the circuit as in Figure
10.6 and connect the output to an oscilloscope. Then write a program
to send data to the DAC at port 1 to generate a stair-step ramp.

Solution:

ORG 0H
CLR A
AGAIN: MOV P1, A ; send data to DAC
INC A ; count from 0 to FFH
ACALL DELAY ; let DAC work and recover
SJMP AGAIN
END
DELAY: MOV R6,#250D
MOV R7,#250D
LABEL1: DJNZ R6,LABEL1
LABEL2: DJNZ R7,LABEL2
RET

You might also like