CS122A-Fall Quarter, 1998


Lab 4 : Analog to Digital Conversion

Prof. Frank Vahid

Purpose:
To be able to implement analog to digital conversion using the ADC0804LCN 8-bit A/D converter. You will design a circuit and program the chip so that when an analog signal is given as input, the equivalent digital voltage is displayed on an LCD display. Thus, in effect, your circuit should function like a simple voltmeter.

Description:
The ability to convert analog signals to digital and vice-versa is very important in signal processing. The objective of an A/D converter is to determine the output digital word corresponding to an analog input signal.
The Datasheet for ADC0804LCN shows the pinout and a typical application schematic. The A/D converter operates on the successive approximation principle. Analog switches are closed sequentially by successive-approximation logic until the analog differential input volatge[Vin(+) - Vin(-)] matches a voltage derived from a tapped resistor string across the reference voltage.
The normal operation proceeds as follows. On the high-to-low transition of the WR input, the internal SAR latches and the shift-register stages are reset, and the INTR output will be set high. As long as the CS input and WR input remain low, the A/D will remain in a reset state. Conversion will start from 1 to 8 clock periods after at least one of these inputs makes a low-to-high transition. After the requisite number of clock pulses to complete the conversion, the INTR pin will make a high-to-low transition. This can be used to interrupt a processor, or otherwise signal the availability of a new conversion. A RD operation(with CS low) will clear the INTR line high again. The device may be operated in the free-running mode by connecting INTR to the WR input with CS=0.
Since this is an 8-bit A/D converter, a voltage from 0-5V. O will be repersented as 0000 0000 (0 in decimal) and 5V is represented as 1111 1111 (256 in decimal). To convert a value X volts to decimal, use the following formula:

          X * 5.0
          -------
            256

To get a better resolution, and display the vlaue as a floating point number, you can multiply the numerator by a factor of 100, 1000 etc. and then print the voltage accordingly.

Assignment:

In this lab, you'll design a program to do the following jobs:

  1. Interface the ADC0804LCN to the 8051
  2. Vary the voltage to Vin(+)
  3. Output the digital value of the voltage on the LCD

Apparatus Required:

  1. ADC0804LCN
  2. 10k resistor
  3. 1k resistor
  4. 5V power supply
  5. Philips PDS51 development board

Schematic:
Refer to the pinout and the application exampl in the Datasheet to connect the ADC0804. The LCD can be connected as was done in the earlier labs.



Program:

#include <reg51.h>
#include "io.h"


sbit RD = P1^2;  /* Define these according to how you have connected the   */
sbit WR = P1^3;  /*         RD, WR, and INTR pins                          */ 
sbit INTR = P1^4;


void main( void ) {

	unsigned char adVal;
	unsigned long volts;
	InitIO();

	RD = 1;
	WR = 1;
	INTR = 1;
	ClearScreen();

        while(1) {

               /* Make a low-to-high transition on the WR input */

               while( INTR == 1 );    /* wait until the INTR signal makes  */
                                       /* high-to-low transition indicating */
                                       /* completion of conversion          */

                         
                /* Read the voltage value from the port */              
                RD = 0;
                adVal = P0;
                RD = 1;

                /* Compute the digital value of the volatge read */

                /* Print the value of the voltage in decimal form */
	}
}
        
Steps to be followed:

  1. Wire up the circuit as shown in the schematic.
  2. Follow the instructions given in Lab 1 to map your network drive, edit, compile and run your program using PDS51.
  3. Follow instructions in Lab 2 to burn a chip and replace it with the emulator in your circuit.

Conclusion:


File translated from TEX by TTH, version 1.1.