You are on page 1of 9

ADC interfacing with Microcontrollers: Introduction

Introduction
In our daily life, anything we deal like sound, prassure, voltage or any measurable quantity, are usually in
analog form So what if we want to interface any analog sensor with our digital controllers? There must be
something that translate the analog inputs to digital output, and so Analog to digital convertors come to play.
Usually we call them ADC (Analog to digital convertor). Before going to learn how to interface an ADC with a
controller we first take a look at basic methods of analog to digital conversion.
This is a sample of the large number of analog-to-digital conversion methods. The basic principle of operation
is to use the comparator principle to determine whether or not to turn on a particular bit of the binary number
output. It is typical for an ADC to use a digital-to-analog converter (DAC) to determine one of the inputs to the
comparator.
Following are the most used converion methods:

Digital-Ramp ADC
Successive Approximation ADC
Flash ADC

Digital-Ramp ADC

Conversion from analog to digital form inherently involves comparator action where the value of the analog
voltage at some point in time is compared with some standard. A common way to do that is to apply the
analog voltage to one terminal of a comparator and trigger a binary counter which drives a DAC. The output of
the DAC is applied to the other terminal of the comparator. Since the output of the DAC is increasing with the
counter, it will trigger the comparator at some point when its voltage exceeds the analog input. The transition
of the comparator stops the binary counter, which at that point holds the digital value corresponding to the
analog voltage.

Successive Approximation ADC


Illustration of 4-bit SAC with 1 volt step size

The successive approximation ADC is much faster than the digital ramp ADC because it uses digital logic to
converge on the value closest to the input voltage. A comparator and a DAC are used in the process. A
flowchart explaning the working is shown in the figure below.

Flash ADC
Illustrated is a 3-bit flash ADC with resolution 1 volt (after Tocci). The
resistor net and comparators provide an input to the combinational logic
circuit, so the conversion time is just the propagation delay through the
network - it is not limited by the clock rate or some convergence
sequence. It is the fastest type of ADC available, but requires a
comparator for each value of output (63 for 6-bit, 255 for 8-bit, etc.)
Such ADCs are available in IC form up to 8-bit and 10-bit flash ADCs
(1023 comparators) are planned. The encoder logic executes a truth
table to convert the ladder of inputs to the binary number output.

Now we lets take a look at the various Analog to Digital convertors that are most commonly used with our
controllers

Name

Description

ADC0800

8-bit ADC

ADC0801

8-bit ADC 100us 0.25 LSB

ADC0802

8-bit ADC 100us 0.5 LSB

ADC0804

8-bit ADC 100us 1.0 LSB

ADC0808

8-bit 8 channel 100us ADC

ADC0809

8-Bit 8 channel ADC (=~ADC0808)

AD571

10-Bit, A/D Converter, Complete with Reference and Clock

MAX1204

5V, 8-Channel, Serial, 10-Bit ADC with 3V Digital Interface

MAX1202

5V, 8-Channel, Serial, 12-Bit ADCs with 3V Digital Interface

MAX195

16-Bit, Self-Calibrating, 10us Sampling ADC

More information on how to interface the above listed ADC can be obtained from the datasheets of respective
ICs. In the next part of tutorial we will look into the interfacing and programming of a simple 8-bit ADC
(ADC0804).

ADC interfacing with Microcontrollers: Interfacing ADC0804

ADC0804 Pinout and Typical Connections

As shown in the typica circuit, ADC0804 can be interfaced with any microcontroller. You need a minimum of 11
pins to interface ADC0804, eight for data pins and 3 for control pins. As shown in the typical circuit the chip
select pin can be made low if you are not using the microcontroller port for any other peripheral
(multiplexing).
There is a universal rule to find out how to use an IC. All you need is the datasheet of the IC you are working
with and take a look at the timing diagram of the IC which shows how to send the data, which signal to assert
and at what time the signal should be made high or low etc.
Note: Keep this in mind that whenever you are working with an IC and you want to know how to

communicate with that IC, then simply look into the timing diagram of that IC from its datasheet. It gives you
complete information that you need regarding the communication of IC.

The above timing diagrams are from ADC0804 datasheet. The first diagram (FIGURE 10A) shows how to start
a conversion. Also you can see which signals are to be asserted and at what time to start a conversion. So
looking into the timing diagram FIGURE 10A. We note down the steps or say the order in which signals are to
be asserted to start a conversion of ADC. As we have decided to make Chip select pin as low so we need not
to bother about the CS signal in the timing diagram. Below steps are for starting an ADC conversion. I am also
including CS signal to give you a clear picture. While programming we will not use this signal.
1.
2.
3.
4.

Make chip select (CS) signal low.


Make write (WR) signal low.
Make chip select (CS) high.
Wait for INTR pin to go low (means conversion ends).

Once the conversion in ADC is done, the data is available in the output latch of the ADC. Looking at the
FIGURE 10B which shows the timing diagram of how to read the converted value from the output latch of the
ADC. Data of the new conversion is only avalable for reading after ADC0804 made INTR pin low or say when
the conversion is over. Below are the stepts to read output from the ADC0804.
1.
2.
3.
4.
5.

Make chip select (CS) pin low.


Make read (RD) signal low.
Read the data from port where ADC is connected.
Make read (RD) signal high.
Make chip select (CS) high.

ADC interfacing with Microcontrollers: Programming for ADC0804

Programming AVR Microcontroller


AVR Assembly Programming for ADC0804
CODE:

.include "8515def.inc"
.equ
.equ
.equ
.equ
.equ
.def
.def

rd = PORTB0
wr = PORTB1
cs = PORTB2
intr = PORTB3
adc_port = PINA
adc_val = r16
temp = r17

.org 0x00
start:
ldi
out
ldi
out

;Read signal PortB.0


;Write Signal PortB.1
;Chip Select PortB.2
;INTR signal PortB.3
;ADC data pins PortA
;To store ADC value
;Temporary register

temp,low(RAMEND)
SPL,temp
temp,high(RAMEND)
SPH,temp

;Load stack with


;RAMEND - highest value
;of internal SRAM

sbi DDRB,rd
sbi DDRB,wr
sbi DDRB,cs

;Make RD as o/p
;Make WR as o/p
;Make CS as o/p

rcall conv
rcall read
ldi temp,0xFF
out DDRC,temp
out PORTC,adc_val
rjmp again

;Start ADC Conversion


;Read ADC conversion

again:

conv:
cbi
cbi
nop
sbi
sbi

;Make PORTC as o/p Port


;Move the read value to PORT C
;Do it again

PORTB,cs
PORTB,wr

;Start conversion
;Make CS low
;Make WR low

PORTB,wr
PORTB,cs

;Make WR high
;Make CS high

wait:
sbic PINB,intr
rjmp wait

;Wait for INTR signal

ret

;Conversion done

read:
cbi PORTB,cs
cbi PORTB,rd

;Read ADC
;Make CS low
;Make RD low

in adc_val,adc_port

;Read ADC data

sbi PORTB,rd
sbi PORTB,cs
ret

;Make RD high
;Make CS high
;Reading done

Programming AVR in C for ADC0804


CODE:

#include <avr/io.h>#define adc_port PINA


//ADC data
pins PORTA
#define rd PB0
//Read signal PORTB0
#define wr PB1
//Write signal PORTB1
#define cs PB2
//Chip Select PORTB2
#define intr PB3
//INTR signal PORTB3
void conv();
void read();

//Start Conversion
//Read ADC value

unsigned char adc_val;


int main(){
DDRB = (1<<rd)|(1<<wr)|(1<<cs);
DDRC = 0xFF;
PORTC = 0xFF;
while(1){
conv();
read();
PORTC = adc_val;
}
return 0;
}

//RD, WR, CS as output


//PORTC as output
//Forever loop
//Start of conversion
//Read converted ADC
//Move it to PORTC

void conv(){
PORTB = PORTB & (~((1<<cs)|(1<<wr))); //Make CS and WR low
PORTB = PORTB | ((1<<cs)|(1<<wr));
//Make CS and WR high
while(PINB&(1<<intr));
//Wait for INTR signal
}
void read(){
PORTB = PORTB & ( ~((1<<cs)|(1<<rd))); //Make RD and CS low
adc_val = adc_port;
//Read ADC port
PORTB = PORTB | ((1<<cs)|(1<<rd));
//Make RD and CS high
}

Programming 8051 Microcontroller


8051 Assembly Programming for ADC0804
CODE:

rd equ P1.0
wr equ P1.1
cs equ P1.2
intr equ P1.3

;Read signal P1.0


;Write signal P1.1
;Chip Select P1.2
;INTR signal P1.3

adc_port equ P2
adc_val equ 30H

;ADC data pins P2


;ADC read value stored here

org 0H
start:
acall conv
acall read
mov P3,adc_val
sjmp start
conv:
clr cs
clr wr
nop
setb wr
setb cs

;Start of Program
;Start ADC conversion
;Read converted value
;Move the value to Port 3
;Do it again
;Start of Conversion
;Make CS low
;Make WR Low
;Make WR High
;Make CS high

wait:
jb intr,wait
ret
read:
clr cs
clr rd
mov a,adc_port
mov adc_val,a
setb rd
setb cs
ret

;Wait for INTR signal


;Conversion done
;Read ADC value
;Make CS Low
;Make RD Low
;Read the converted value
;Store it in local variable
;Make RD High
;Make CS High
;Reading done

Programming 8051 in C for ADC0804


CODE:

#include <REGX51.H>#define adc_port P2


//ADC Port
#define rd P1_0
//Read signal P1.0
#define wr P1_1
//Write signal P1.1
#define cs P1_2
//Chip Select P1.2
#define intr P1_3
//INTR signal P1.3
void conv();
void read();

//Start of conversion function


//Read ADC function

unsigned char adc_val;


void main(){
while(1){
conv();
read();
P3 = adc_val;
}
}

//Forever loop
//Start conversion
//Read ADC
//Send the read value to P3

void conv(){
cs = 0;
wr = 0;
wr = 1;
cs = 1;
while(intr);
}

//Make
//Make
//Make
//Make
//Wait

CS low
WR low
WR high
CS high
for INTR to go low

void read(){
cs = 0;
rd = 0;
adc_val = adc_port;
rd = 1;
cs = 1;
}

//Make
//Make
//Read
//Make
//Make

CS low
RD low
ADC port
RD high
CS high

You might also like