Interfacing  ADC to Microcontroller Chip 8051

 

Article by: Nagabhooshan S.Shet

            Now a day the digital inventory are working a revolution in the field of technology, microcontrollers, microprocessors are used more effectively than those of analog circuitry. But the output of any sensors which deals with physical equality like temperature, humidity, pressure, viscosity, velocity which are used most of the data acquisition flat forms are in the form of analog signals or continuous signals. Microcontrollers, microprocessors are do nothing with these signals. Because they require the signal in the form of binary numbers. So we should convert these analog signals into digital format. Then here comes ADC (Analog to digital  converters) in picture.  

 

            ADC are more widely used devices in digital technology. This ADC converts an analog data into a binary coded data which can be fed directly to the digital processors. Here we use an analog to digital  converter chip ADC 0804 which is widely used by the digital computing designers.

 

          ADC 0804 chip has 8 bit resolution which works on a +5v supply.  The fact that influences while selecting an ADC is its conversion time.  The conversion time is nothing but the time taken by the ADC to convert an analog data into its respective digital data or into a binary number.  This time is depends on the respective digital data or into a binary number. This time is depends on respective ICs.  In ADC 0804 this time can be controlled by using two external components resister and capacitor which is explained in detail in the coming section. ADC 0804 chip has some input signals which can control performance of the chip.  This control signal is sent by the microcontroller 8051. 

 

Pin diagram of ADC 0804 Chip.

 

 Now we see these control inputs in briefly.

 

I). Chip Select (CS) :

Chip Select (CS) is an input which activates the ADC 0804 chip.  Whenever this chip is to be functioned this CS input is activated. For  ADC 0804 chip select is an active low input.  So whenever you want ADC 0804 chip is to be function this pin is made low.

 

ii). Write (WR):

     This is a control signal which tells ADC chip to start the conversion of  analog data to binary format.  This is the active low input.  When the Chip Select (CS) is at zero logic level, and a low to high going pulse is applied to write pin of ADC chip, chip starts the conversion of the analog signal at its input terminal into 8-bit binary output.  The conversion hence depends on the input clock (CLKIN) and CLKR inputs.  This signal is also referred as �start conversion�  signal. 

 

iii). CLK IN and CLKR:

     These two pins determines the conversion time.  When an external clock signal is applied for the timing CLK IN pin is connected to the external clock signal. 

    But there is an extra feature in ADC 0804 chip. It has its own internal clock generator. If one wants to use this internal clock signal CLK IN and ClKR are connected to resister and capacitor respectively.  In this case the clock frequency is calculated by

f = 1/ 1.1 RC    Hz

where R is the resistance value and C is the capacitance value.  Normally we use R=10 k and C=150pF and this value is standardized.  We get the frequency as 606KHz and conversion time 110 micro seconds.

 

iv). Read (RD):

     Read is an input signal. This signal also called output enable. When the conversion completes the ADC chip 0804 stores the converted data in its internal registers.  To get this data as output,  read (RD) signal is applied.  For this ADC chip RD is an active low signal.  When the data is to be read a low signal is sent to RD pin keeping  the CS pin low.  The converted 8 bit data is available on the output pins D0 to D7.

 

v). Interrupt (INTR) :

     Interrupt is an output signal given by the ADC chip.  This signal is used as an input signal to microcontroller normally this signal is at logic high.  When the conversion completes the ADC produces an active low interrupt signal.  When this happens to read the converted data the read signal is to be applied to ADC 0804 keeping CS signal low.  This signal is also referred �end of conversion� signal.

 

vi). Vin (+) and Vin(-):

    These are two differential analog input.  The effective Vin is Vin (+) � Vin (-). Normally analog signal is applied to Vin (+) keeping Vin (-) to ground.  Vin should not be exceeded than + 5V.

 

vii). Vref/2 :

     This is as reference voltage.  To vary the range of signal voltage this pin is used.  This pin is kept at a potential deference half of the Vin applied.  The maximum Vin can be applied is + 5V.  When Vref/2 pin is kept open ADC reads to voltage from 0 to 5V.

 

viii). D0 � D7 :

    These are the 8 bit binary output pins of ADC 0804 chip.

ix). VCC :

     This is a power supply used for the proper functioning of ADC chip.  Normally this voltage is + 5v.

x). Ground (GND):

     There are two ground pins in ADC chip.  Analog ground and digital ground.

          Analog ground is connected to the ground of analog signal source and digital ground is connected to the ground of the Vcc source.  This is done  to isolate the analog in signal from transient voltages caused by digital switching of the output D0-Dand for accuracy of the digital output of analog input signal. 

 

Circuit diagram of interfacing ADC to Microcontroller

 

The programming of ADC to microcontroller is as follows,

Making port P1 of 8051 as an input port to get the binary coded number from ADC  and port P3 to send the control signals to the ADC chip.

(   P3.0 - interrupt from ADC; P3.1 - write signal; P3.2 - read signal; )

Port P2.0-P2.4 to display the voltage level.

 

Here we are monitoring the various voltages using LEDs.

1. Chip select (CS) is made low to activate ADC 0804 chip.

2. Read (RD) is made low to get the data out of the chip ADC 0804.

3. To start the conversion process sending low-to-high pulse to WR pin with holding CS=0.

4. When the conversion of data is completed the INTR pin goes low. So give some delay for completing conversion

5. Input the data from the port PORT P1 to accumulator .

6. To control devices according to i/p voltage by comparing the input data with various reference data like CCh,99h,66h,33h,00h with 4v,3v,2v,1v respectively .

7. While subtracting if carry flag is set, compare the content with lower reference voltages.

8. Suppose carry bit is not set. Then activate respective devices by making one of the respective output line high.

9. Repeat the step for next voltage levels by following step 2.

Start of main program:       

        start:      mov p1,#0ffh

                                 clr p3.1          ;(WR) to start the conversion

                                 setb p3.1        ;process sending low-to-high pulse        

                 here:       jb p3.0, here  ;(INTR) to check whether the conversion is

                                                                finished

 

                                mov a,p1          ;input the data from the port P1   

                                mov r2,a

 

we scale the various voltages

                                mov a,r2            ;getting back the stored data

                                subb a,#0cch    ;check whether [a]> 4volt  

                                jc 4v

                                setb p2.0            ;glow 1st  LED

                               

                       4v:    mov a,r2

                                subb a,#99h       ;check whether [a]> 3volt  

                                jc 3v

                                setb p2.1            ;glow 2nd LED

 

                       3v:    mov a,r2

                                subb a,#66h       ;check whether [a]> 2volt   `     

                                jc 2v

                                setb p2.2         ;glow 3rd  LED

 

                       2v:    mov a,r2

                                subb a,#33h       ;check whether [a]> 1volt            

                                jc 1v

                                setb p2.3            ;glow 4th  LED

 

                       1v:    mov a,r2

                                subb a,#11h       ;check whether [a]> 0volt         

                                jc start

                                setb p2.4           ;glow 5th LED

 

 

 

contact the author at shet4u@rediffmail.com