Sunteți pe pagina 1din 15

INTERFACING ADC WITH

8051
Introduction
• Many times we need to collect data from different sensors
and many sensors give us data in analog form.
• Output from some sensors such as humidity, temperature
(thermistor), light (LDR), pressure is in analog form.
• So, analog to digital converters (ADC’s) are required to
convert the analog output of these sensors to a digital code.
• ADC’s convert the analog quantity (mostly voltage) to a
digital number.
• Some microcontrollers like Atmel AVR and Microchip PIC
have inbuilt ADC’s. But 8051 microcontroller needs an
external ADC.
ADC808
• ADC0808 is most commonly used analog to digital
converter.
• It is an 8-bit analog to digital converter IC.
• It converts an analog input to 8-bit digital code.
• The number of discrete levels produced by ADC for a given
analog input range is called resolution of ADC.
• ADC0808 has a resolution of 8-bits which means for a given
analog input range it can produce 256 (2n) levels or 256
digital codes.
• Suppose our input voltage range is 0 to 1 volt. In this case
output of ADC0808 will be 00H for 0 volt and it will be FFH
for 1 volt.
ADC808
• ADC0808 uses the successive approximation technique for
conversion and the conversion time is around 100µs.
• It has 8 analog input channels and 8-channel multiplexer for
selecting a particular channel.
• We can connect 8 sensors or 8 analog sources to ADC0808.
• The inbuilt 8-channel multiplexer has 3 select lines A, B and C.
• We can select any channel from 0 to 7 by giving digital input
(either 0 or 1) to these lines.
• Pin number 22 of ADC0808 ALE (address latch enable) is used
to latch the address from select lines A, B and C.
ADC808 Configuration
• Pin number 12 and 16 are vref+ and vref- pins for setting the reference
voltage. By setting the reference voltage we can find step size.
Q = Vref (+) – Vref (-)/2n

• Where Q is the step size and n indicates the resolution of ADC. For a voltage
range of 0 to 1 volt, step size will become 3.90625mV.

• Pin number 10 is for providing external clock to ADC0808. The range of


clock frequency is 10 KHz to 1280 KHz. Clock frequency can be generated
either by using 555 timer IC or by using internal timer of 8051
microcontroller.

• In circuit diagram, output of ADC0808 is connected to Port 1 of 8051


microcontroller. The address lines A, B and C are connected to P2.4, P2.3 and
P2.2 respectively. ALE is connected to P2.1.

• Timer0 of 8051 is used for generating clock frequency for ADC0808. Timer0
is used in mode 2 i.e. 8-bit auto-reload mode. Interrupt for timer0 is enabled.
Every time the interrupt is generated P2.5 pin toggles its state.
Steps to program ADC0808:
• Firstly provide bits to address lines or select lines A, B and C to
select an input channel (IN0 to IN7).

• Provide a low (0) to high (1) pulse to ALE, so it can latch the
address from address lines.
• Give a high (1) to low (0) pulse to SOC to indicate start of
conversion.

• Continuously monitor the EOC [End of Conversion] for end of


conversion.
• Provide a high (1) to low (0) pulse on OE to get 8-bit digital data
(output).
Circuit Diagram
Code
#include<reg51.h>
sbit soc = P2^6;
sbit eoc = P2^7;
sbit oe = P2^0;
sbit ada = P2^4; //address line A
sbit adb = P2^3; //address line B
sbit adc = P2^2; //address line C
sbit ale = P2^1;
sbit clk = P2^5;

#define dout P1 //taking digital output on port 1


float x = 0;
void msdelay(unsigned int delay)
{ int i,j;
for(i=0;i<delay;i++)
{ for(j=0;j<120;j++); }
}
void timer0() interrupt 1 //providing clock to ADC0808 through timer
{
clk = ~clk;
}
void analog_to_digital()
{ ada = adb = adc = 0; //Selecting first channel IN0
eoc = 1;
soc = 0;
oe = 1;
msdelay(20);
ale = 0;
msdelay(20);
ale = 1;
msdelay(20);
soc = 1;
msdelay(20);
soc = 0;
while(eoc == 1);
while(eoc == 0);
oe = 1;
x = dout;
oe = 0;
}
void main ()
{
dout = 0xff;
TMOD = 0x22;
TH0 = 0xfd;
IE = 0x82;
TR0 = 1;

while(1)
{
msdelay(1000);
analog_to_digital();
x = x*0.00390625; //For a voltage range of 0 to 1 volt
}
}
INTERFACING DAC WITH
8051
Introduction
• The digital-to-analog converter (DAC) is a device
widely used to convert digital pulses to analog signals.

• There are two methods of creating a DAC:


• Binary weighted and
• R/2R ladder.

• The vast majority of integrated circuit DACs, including


the MC1408 (DAC0808) used in this section, use the
R/2R method since it can achieve a much higher degree
of precision.
Introduction
• The vast majority of integrated circuit DACs, including the
MC1408 (DAC0808) used in this section, use the R/2R method
since it can achieve a much higher degree of precision.
• The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs. The common ones are
8, 10, and 12 bits.
• The number of data bit inputs decides the resolution of the DAC
since the number of analog output levels is equal to 2″, where n
is the number of data bit inputs.
• Therefore, an 8-input DAC such as the DAC0808 provides 256
discrete voltage (or current) levels of output.
• Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
• There are also 16-bit DACs, but they are more expensive.
DAC Working
• In the MC1408 (DAC0808), the digital inputs are converted
to current (Iout), and by connecting a resistor to the Iout pin,
we convert the result to voltage.
• The total current provided by the Iout pin is a function of the
binary numbers at the DO – D7 inputs of the DAC0808 and
the reference current (Iref), and is as follows:

S-ar putea să vă placă și