sensor reading problem

Thread Starter

sahar

Joined Oct 23, 2008
4
hi
every one
i'm doing a project to control light intensity within a room at89c51 interfacing with adc0808.i have used 3 light sensors with pin 26,27,28 of adc.this system always send the reading 255 whether sensors are connected or not.i cant understand the problem.plz help me to solve the problem.i follow the code mentioned below.is any problem in my code or i will check my circuit.

#include<reg51.h>
void se(unsigned char x);
void con(unsigned char value);
void ms(unsigned int value);

sbit clock=P3^2;
sbit ALE=P3^6;
sbit OE=P3^5;
sbit SC=P3^3;
sbit EOC=P3^4;

sbit Addr_A=P1^0;
sbit Addr_B=P1^1;
sbit Addr_C=P1^2;

sbit Relay1=P1^3;
sbit Relay2=P1^4;
sbit Relay3=P1^5;
sbit Relay4=P1^6;
sbit Relay5=P1^7;

unsigned char lux;
unsigned char array[]={'0','1','2','3','4','5','6','7','8','9'};

void timer0() interrupt 1
{
clock=~clock;
}
void serial0() interrupt 4
{
if(RI==1)
{
se('P');
RI=0;
lux=SBUF;
switch(lux)
{
case ('a'):
Relay1=1;
se('a');
break;

case ('A'):
Relay1=0;
se('A');
break;

case ('b'):
Relay2=1;
se('b');
break;

case ('B'):
Relay2=0;
se('B');
break;

case ('c'):
Relay3=1;
se('c');
break;

case ('C'):
Relay3=0;
se('C');
break;

case ('d'):
Relay4=1;
se('d');
break;

case ('D'):
Relay4=0;
se('D');
break;

case ('e'):
Relay5=1;
se('e');
break;

case ('E'):
Relay5=0;
se('E');
break;

default :
se('N');
}
RI=0;
}
}

void main(void)
{
unsigned char value;

P2=0xFF;
EOC=1;
ALE=0;
OE=0;
SC=0;

TMOD=0x22;
TH1=0xFD;
SCON=0x50;
EA=1;
ES=1;
// IE=0x92;
TR1=1;
TI=0;
RI=0;

// get data from adc
while(1)
{
//use channel 0
ms(30000);
se('X');
se('O');
se('P');
Addr_A=0;
Addr_B=0;
Addr_C=0;
ms(255);
ALE=1;
ms(255);
SC=1;
ms(255);
ALE=0;
SC=0;
while(EOC==1);
while(EOC==0);
OE=1;
ms(255);
value=P2;
OE=0;
con(value);
se('X');
//use channel 1
ms(30000);
se('y');
Addr_A=1;
Addr_B=0;
Addr_C=0;
ms(255);
ALE=1;
ms(255);
SC=1;
ms(255);
ALE=0;
SC=0;
while(EOC==1);
while(EOC==0);
OE=1;
ms(255);
value=P2;
OE=0;
con(value);
se('Y');
//use channel 2
ms(30000);
se('z');
Addr_A=0;
Addr_B=1;
Addr_C=0;
ms(255);
ALE=1;
ms(255);
SC=1;
ms(255);
ALE=0;
SC=0;
while(EOC==1);
while(EOC==0);
OE=1;
ms(255);
value=P2;
OE=0;
con(value);
se('Z');
}
}
void ms(unsigned int value)
{
unsigned int x,y;
for(x=0;x<value;x++);
for(y=0;y<1275;y++);
}
void con(unsigned char value)
{
unsigned char x,d1,d2,d3;
x=value/10;
d1=value%10;
d2=x%10;
d3=x/10;
se(array[d3]);
ms(255);
se(array[d2]);
ms(255);
se(array[d1]);
ms(255);
}
void se(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}

thanks in advance
 

beenthere

Joined Apr 20, 2004
15,819
A post of the circuit would help.

Also, present the A to D with a known voltage that is less than full scale. If the conversion remains at FFh, then you know that there is a problem with either the A to D or in the connection to the uC.
 

Thread Starter

sahar

Joined Oct 23, 2008
4
thanks 4 your reply and kind attention to my problem.my ground pin was not properly connrcted.but now i 'm facing a new problem i.e adc give reading 64 instead giving 0.
i'm using the following circuit.

View attachment circuit.doc

i check the variation of the output value from adc against varying input voltage to IN pins of adc.i connected light sensor through 10k veriable resistor to the IN0,IN1,IN2 pins of adc.i did following experiment to check my circuit.
1) i kept the distance between the sensor and light source constant and gave the input voltage of 1V,2V,3V,4V by changing resistance from veriable resistance.
2) secondly i kept the variable resistance constant at min resisance and gave input voltage 1V,2V,3V,4V from sensor attached IN0 pin by changing the distance b/w sensor and source.
i got the following result

inputvoltage.............with constant distance..........with constant variable...........expected value
.............................................varying variable...................varying distance

0................................................64................................................64........................................0
1...............................................116...............................................113.....................................51
2...............................................104...............................................112...................................102
3...............................................227...............................................231...................................153
4...............................................217...............................................202...................................204

i could not get the true value.
i also changed the reference voltage from 2.56 to 5 volts and variable resistance from 1k to 10k and old adc from new one but there was no change in result.
plz tell me how i can get true value from my circuit.
 

beenthere

Joined Apr 20, 2004
15,819
What happens if you simply read one input? Does it follow the input from 0 volts to +5 volts? As an experimental setup, use a potentiometer control to supply the input voltage.
 

Thread Starter

sahar

Joined Oct 23, 2008
4
no need of it now.actually pin p^6 of at89c51 is not properly connected so at every time this bit was on so it give 64 instead of 0.circuit and software both are correct and its working well.again thank u :)
 
Top