# ADC0808 conversion algorithm

#### FBorges22

Joined Sep 11, 2008
109
Greetings,

I am trying to use the ADC0808 with the 8051 microcontroller. But I am having a little trouble in the conversion of the device. Recently I programmed these functions to pulse the necessary pins of the device according to datasheet

The code is below

Rich (BB code):
void adc_convert()
{
P2_0=0;
P2_1=0;
P2_2=0;
delay_small();
// Pulses the ALE and the START respectvely to starts the conversion...
P2_3=1;
delay_small();
P2_4=1;
delay_small();
// Disables the ALE and START...
P2_3=0;
delay_small();
P2_4=0;
}

void send_portP1()
{
xtod(P1);
SBUF=0x30+Hundreds_Cnt;
while(!TI);
TI=0;
SBUF=0x30+Tens_Cnt;
while(!TI);
TI=0;
SBUF=0x30+Ones_Cnt;
while(!TI);
TI=0;
SBUF=0x0A; // Sends the "\n"
while(!TI);
TI=0;
}

void int0() interrupt 0
{
P2_5=1; // Enables the OE
delay_small();
P2_5=0; // Disables the OE
while(IE0);
send_portP1();
REN=1;
P2=0x00;
}
Basically the P2 port is connected to the control lines of the ADC and the P1 port is connected to the data bus of the ADC. I tested this program in the HyperTerminal and the serial communications is ok but the ADC is still not converting...

The enviroment of the experiment was in these conditions:

12MHz of clock for the 8051 uC
1MHz of clock for the ADC0808

#### StayatHomeElectronics

Joined Sep 25, 2008
1,070
When you say that the ADC is not converting, do you mean that you never get the EOC, End of Conversion, interrupt?

I am not up on my processor code so I may be wrong. It looks like you enable the OE, Output Enable, delay, and disable it again. Do you read it at all while it is enabled? It looks like you read it after it is disabled again.

#### FBorges22

Joined Sep 11, 2008
109
Yes, I am not getting the EOC interrupt.

How I can fix this error?

#### StayatHomeElectronics

Joined Sep 25, 2008
1,070
Do you have an oscilloscope so you can look at the EOC signal to see if it is actually doing anything?

Is your interrupt set in the software to be a rising edge or a falling edge?

Is your start timing correct? Does your 8051 produce a signal similar to that of the timing diagram? Can you verify on an oscilloscope? Can you post what the waveforms look like, clock, ALE, START, EOC?

#### FBorges22

Joined Sep 11, 2008
109
I will check in the oscilloscope and post the results soon enough... In the mean time to start the conversion in the ADC I need to pulse the ALE and the START pins respectively right?

#### StayatHomeElectronics

Joined Sep 25, 2008
1,070
That is right.

#### FBorges22

Joined Sep 11, 2008
109
Ok,

I pulsed the START and ALE pins but nothing happens when I try to read the data from the ADC when que uC receives the "b" character in the serial port.

Recently I tried to bypass the INT0 pin using a switch and the interrupt was triggered and the state from the P1 port was sent and the value was 78... I was expecting 255 because nothing is connected in the ADC analog input.

Here is a piece of the code from my program:

Rich (BB code):
void delay_small() _naked
{
_asm
nop
ret
_endasm;
}
{
P2_0=0;
P2_1=0;
P2_2=0;
delay_small();
// Pulses the ALE and START pins to start the conversion
P2_3=1;
delay_small();
P2_4=1;
delay_small();
// Lower the ALE and START...
P2_3=0;
delay_small();
P2_4=0;
}
void send_portP1()
{
decimalConvert(P1);
SBUF=0x30+Hundreds_Cnt;
while(!TI);
TI=0;
SBUF=0x30+Tens_Cnt;
while(!TI);
TI=0;
SBUF=0x30+Ones_Cnt;
while(!TI);
TI=0;
SBUF=0x0A; // envia o caractere "\n"
while(!TI);
TI=0;
}
void int0() interrupt 0
{
while(IE0);
delay_small();
P2_5=1; // Habilita o OE
delay_small();
send_portP1();
P2_5=0; // Desativa o OE
REN=1;
P2=0x00;
}
void receive_serial() interrupt 4 using 0
{
while(!RI);
RI=0;
sbuffer=SBUF;
switch (sbuffer)
{
case 0x61: send_portP1(); break;
case 0x62: adc_convert(); break;
case 0x63: P2=0x00; break;
default: break;
}
}
What could be wrong? Why the ADC is not converting? Have anyone used this ADC with the 8051? Here is the clock waveforms...

#### Attachments

• 60 KB Views: 15
• 58.4 KB Views: 21