The data we process in a microcontroller normally deals with digital signals. But there may a situation where we have to deal with external inputs such as analog signals. All most all the input signals from physical sensors are of analog signals. In such cases, we can interface the microcontroller with an external device such as an ADC0808 to convert the analog signal to a digital signal. Because our microcontrollers can only understand 0 and 1. In this article, we look into the details of ADC interfacing with 8051.

In the present time, there are lots of microcontrollers in the market which has inbuilt ADC with one or more channels, E.g.: PIC18F4550, LPC1768, etc. And by using their ADC registers we can interface. Unfortunately, 8051 doesn’t have an internal module so we will go for an external ADC. which is ADC0808.

ADC0808 :

ADC0808 is a commonly used External 8 bit ADC and it has 28 pins. It can measure up to eight ADC values from 0 to 5 volt since it has eight channels. when voltage reference is +5V, its Step size will be 19.53mV. That is, for every increase of 19.53mV on the input side there will be an increase of 1 bit at the output side.

ADC0808 needs an external clock to operate. The ADC needs some specific control signals for its operations like start conversion and bring data to output pins. When the conversion is complete the EOC pins go low to indicate the end of a conversion and that the data is ready to be picked up.

Features

  • Easy interface to all microprocessors
  • Operates ratio metrically or with 5 V DC or analog span adjusted voltage reference
  • No zero or full-scale adjust required
  • 8-channel multiplexer with address logic
  • 0V to 5V input range with single 5V power supply
  • Outputs meet TTL voltage level specifications
  • Standard hermetic or molded 28-pin DIP package
  • 28-pin molded chip carrier package

Pin diagram

adc0808 pin diagram

Channel Selection :

We can select any input channel by using the Address lines ADD A, ADD B and ADD C. As you can see in the below table, We can select the input line IN0 by keeping all three address lines ADD A, ADD B and ADD C Low.

adc0808 channels.

Steps to be followed to interface ADC (ADC0808) with 8051

  1. Start
  2. Select the channel using Address pins.
  3. A Low – High transition on ALE to latch in the address.
  4. A Low – High transition on Start to reset the ADC’s SAR.
  5. A High – Low transition on ALE.
  6. A High – Low transition on start to start the conversion.
  7. Wait for End of cycle (EOC) pin to become high.
  8. Make Output Enable pin High.
  9. Take Data from the ADC’s output
  10. Make Output Enable pin Low.
  11. Stop

Steps to calculate voltage.

Voltage value for each increase of bit can be found using the equation :

Step Size = (Vref+ – Vref-)/256
Step size can be multiplied with ADC output to get the voltage.

Example :

If Vref+ is connected to 5v and Vref- is connected to ground the equation becomes :

Step size = (5 – 0)/256= 19.53 mv

In such a case if the output value is 01101110 = 110

The voltage value will be : 110 x 19.53 mV = 2.14 V .

ADC(ADC0808) interfacing with 8051 ( AT89S52 )

Circuit Diagram

The following circuit shows the interfacing of ADC with 8051. In this circuit, we have used AT89S52 as an 8051 microcontroller and ADC0808 as an external ADC module. we will use a Potentiometer to vary the voltage. It is connected to channel 0 of the ADC0808. instead, if you want you can use real sensors. Also, to display the output we will use a 16×2 character LCD. We have connected the output of ADC0808 to port 1.



Program Explanation for ADC(ADC0808) interfacing with 8051:

First, we will include header files and define variable and input & output pins for ADC and LCD.

We will give the clock for the ADC module using our controller itself s, for that, we have made a Function to generate a clock of frequency 500KHZ using Timer 0 interrupt.

Functions are made for delay and LCD.

In the function adc() first, the required channel is chosen using ADD A, ADD B and ADD C pins. After which read_adc() function is called. In read_adc() function, we wait for the conversion and the output is given to the variable ADC_value. which is then displayed after converting to string.

In the main function timer 0 interrupt is configured for the clock to drive ADC0808. LCD and the ADC0808 is also initialized.
A while(1) loop has been created to read and display the ADC value again and again.

Liked this article! You'll love our video courses.
Checkout our comprehensive pre-recorded Video Courses for 8051 Microcontrollers
More details
Spread the love, share this