Interfacing ADC 0808 with 8051

In most of the digital system micro controller needs to take input from Analog sensor or transducer. Analog signal are most common input signal for embedded system. Sensor or transducer Such as Temperature, Motion, pressure, Humidity are analog. You will need to design a circuit to program AT89c51 or 8051 for converting analog input to equivalent digital data.  

I/O Pin Details   
Analog Channel Selection
ADC 0808 have 8 different channel. For proper channel selection logic as per table is provided to Pin no. 23, 24,25.


Reference Voltage or Step Size
Step Size or Reference voltage can be calculated from equation Step Size = (VREF(+) + VREF(-))/2 If we consider VREF(-) = Gnd and VREF(+) = 5V then step size = 5/256 = 19.53 mV. If you using temperature sensor LM35 then step size is 10 mV. 10 mV step size can be set by VREF(-) = Gnd and VREF(+) = 2.56V.

ALE 
ALE (Address Latch Enable) is L - to H pulse to latch in address.   

START
ADC starts conversation on receiving this signal high to low. Successive approximation register (SAR) is reset on the positive edge of the start conversion (SC) pulse. The conversion is begun on the falling edge of the start conversion pulse.   

EOC (End Of Conversion)
 This is an active low O/P signal from ADC on receiving low EOC micro controller Come to know that the converted data is ready to be picked up.

OE (Output Enable)
ADC converts the analog input to its binary equivalent and holds it in an internal register. L- to-H OE is used to enabling TRI - STATE output, so Converted data can be red from data pin D0 – D7.

Clock signal
Clock signal cannot be faster then 100ms.It can be external or provided from microcontroller crystal using 4 D- F/F as frequency divider. Single D- F/F divides frequency by 2.

Signal conditioning
If sensor signal is very low then apply proper amplification. You need simple opam amplifier. Normally sensor O/P is in range of mV and affected by noise very easily for better accuracy apply 2 - 5 gain. If you using temperature sensor LM35 its O/P is 10mv/C and it is advised to amplification by gain of 2 – 5.

Circuit Diagram

Interfacing ADC 0808 with 8051

Algorithm to program the ADC 0808 through AT89C51

1)      Connect the ADC as shown in diagram. Provide Clock signal from micro controller crystal by step down its frequency with help of D – F/F.
2)      Select the analog channel. If necessary apply proper signal conditioning as mentioned.
3)      Provide Low to High transition on ALE to latch in the address
4)      Provide Low to High transition on SC to let ADC to initiate converting from selected analog channel to equivalent digital bit.
5)      Now monitor for EOC signal from ADC to high to low. H- to-L EOC indicates that data is ready to collect.
6)      Now finally make OE L- to-H to read data from internal buffer.

Click Hear to download Program and Proteus, Keil Simulations Download

Timing Diagram


Program
Click Hear to download Program and Proteus, Keil Simulations Download


ORG 0000H
ADC_DATA EQU P1                        ; Define Name to Port Pins
ADC_SC BIT P3.0
ADC_EOC BIT P3.1
ADC_ALE BIT P3.2
ADC_OE BIT P3.3
ADD_A BIT P3.4
ADD_B BIT P3.5
ADD_C BIT P3.6
            MOV ADC_DATA,#0FFH      ;Assign port 1 as I/P port
            SETB ADD_A                        ; channel selection
            SETB ADD_B
            CLR ADD_C                           ; Here channel no 3 is selected
            ACALL DELAY1
MAIN:
            ACall ADC_CON       
            MOV P0,A
            SJMP MAIN
;ADC Programming Start
ADC_CON:
            SETB ADC_EOC                     ; Make EOC AS Input Port
            CLR ADC_ALE
            CLR ADC_SC
            CLR ADC_OE
BACK:
            SETB ADC_ALE                     ; Give High to Low Pulse to Latch Address
            ACALL DELAY1
            SETB ADC_SC                        ; Give High to Low Pulse for Start of Conversion
            ACALL DELAY1
            CLR ADC_ALE
            CLR ADC_SC
HERE12:
            JB ADC_EOC,HERE12           ;Wait till ADC Complete Its Task
HERE11:
            JNB ADC_EOC,HERE11        ;After ADC Put Data To Output Signal Goes High Again
            SETB ADC_OE                       ; Set OE High For converted Data to Available on Controller,
            ACALL DELAY1                    ; For Further Operation
                                   
            MOV A,ADC_DATA               ;Load Data To Acc.
            CLR ADC_OE                         ; Save Converted Digital Data on Memory
;           MOV B,#05H                           ;If signal are very small from sensor (such as                                                             ; Temperature SensorLM35)
;           DIV AB                                   ; then amplify. Provide amplifier gain in place of                                                             ; 05H for obtaining real digital data                            
            RET                                         ; Return To Main Routine
; Delay
; App. 1.2749 Sec. Delay
DELAY:
            MOV R3,#9
HERE13:
            MOV R1,#255
HERE21:
            MOV R2,#255
HERE31:
            DJNZ R2,HERE31
            DJNZ R1,HERE21
            DJNZ R3,HERE13
            RET
; App. 243 ยต Sec.
DELAY1:       
            MOV R3,#1
HERE1:
            MOV R1,#10
HERE2:
            MOV R2,#10
HERE3:
            DJNZ R2,HERE3
            DJNZ R1,HERE2
            DJNZ R3,HERE1
            RET
            END

Click Hear to download Program and Proteus, Keil Simulations Download