PDA

View Full Version : Problem with ADC

qwerty
02-08-2008, 08:43 PM
We are trying to interface IR sensor with the uC through ADC0808.
XTAL frequency of uC is 11.0592 MHz. So to reduce it to be able to use the same XTAL for ADC clock we have used 74LS74 (D flip-flops).

The program which we have burned into the uC is as follows:

// for uC take input (from ADC) at P1, output it at P3, use P2 for special ADC pins

#include<reg51.H>
sbit ALE=P2^4;
sbit OE=P2^5;
sbit SC=P2^6;
sbit EOC=P2^7;
void main()
{
unsigned char value;
unsigned char i;
P1=0xFF; //input
P3=0x00; //output
EOC=1;
ALE=0;
OE=0;
SC=0;
while(1)
{
for(i=0;i<1000;i++);
ALE=1;
for(i=0;i<1000;i++);
SC=1;
for(i=0;i<1000;i++);
ALE=0;
SC=0;
while(EOC==1);
while(EOC==0);
OE=1;
for(i=0;i<1000;i++);
value=P1;
OE=0;
P3=value;
}
}

The problem is that whatever be the input to the ADC, the uC shows zero at all pins on P3.
I dont know if there is any error in my electrical circuit or the programming part.
Any help will be of great value.

debu
02-09-2008, 10:01 AM
@Qwerty: I think I know what your problem is. You have probably tied the Pin 10 (Clock) to your Xtal. This wont work.

You need to use the ADC0808 asynchronously, i.e, you need to clock out the values from the ADC by sending pulses on the Clock pin. The clock pin take no more then 640KHz pulses.
Use plenty of NOP's, so you don't exceed the max rating. Your code should look like:

CONTROL EQU P3
START EQU P3.3
EOC EQU P3.4
OE EQU P3.5
ALE EQU P3.6
DATA EQU P1

MOV CONTROL,#00H
MOV DATA,#FFH
MOV A,BUFFER
ANL A,#07H
ANL CONTROL,#F8H
ORL CONTROL,A
SETB ALE
NOP
NOP
SETB START
NOP
CLR ALE
NOP
NOP
CLR START
NOP
NOP
JMP do_op