Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

sensor readings floating when interfaced with pic16f877a

Status
Not open for further replies.

rangerskm

Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,663
i connected various types of sensors such as temperature,co sensor,humidity sensor.these all works fine before a year in another board,now i interfaced these sensors with new pic controller board.but the sensor value varies as 0 and peak value in frequent manner.whats the reason for this??

can any one say a solution for this
 

Did you check the connections of the new board are the same of the old one ? You sensors are interface digitally or they are analog, connected to an ADC ?
 
hi bro

i connected same as old one.i connected as analog pin which is same as old one.i need to know any noise will occur in the sensors when interfacing??
 

It seems like there is no ground connection between sensor and control board. Did you also check, by means of a multimeter, that the sensor power supply is OK ?
 
yeah generally i face this problem when ground is not connected properly
 

how the connections should made for ground ,shall we want to put any resistors ??
 

NO!!! and all connections should be intact. Power supply should be stable. Its always recommended to use decoupling caps at all places possible.
 
where we have to connect the capacitors??
 

I think your board is DC coupled then no capacitors are required. However if you could post the schematic or the data-sheet of the board and the sensors (the page where the analog connections are specified) or let's know the brand and model we can have a look to that and better help you.
 
yes bro..my board is dc coupled.i checked with the multimeter the power supply is stable.is it due to floating of analog input pins??
 

OK, could you also check the output of your sensor, with a multimeter ? As I said it seems the ground of your sensor is not connected with the ground of the board. For instance it cpould be that the pin out of the new board is different from the old one and a pin that was ground is now an inout pin, so the sensor is connected between two input pins instead been connected between input and ground.
 
bro.. then my sensor voltage readings show 5v as i applied and output shows constant in some volt eg 1v then it suddenly increases to 1.5v then to 1 v .the readings are changing like this only.lot of soldering works done in the new board all the sensor values fluctuating.dont know whether its due to soldering or not.some minor volt changes in output of sensor will affect the output readings right??
 

Code:
#include<pic.h>


#define enter 0x0d
#define ctrlz 0x1a

#define sendb RC0

#define rs RD6
#define rw RD5
#define en RD7
#define lcdport PORTB

int convert[16]='0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F';
int lcd[16]=0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78;
unsigned int x,temp,adc_value,countdata,digit1,digit2,digit3,digit4,digit5,air,temperature,humidity,sound,water,time;
unsigned int vd,lat[11],lon[12];

void initialisemodem();
void deleteallmsg();
void sendtestmsg();
void send_data();
void snumber();			//stored number
void readmessage();

void read_gps();

void hextobcd();
void acd_config();
void adc_data_accure();
void acd_read(int);

void delay(int);

void initialise_lcd();
void command(int);
void display(int);
void dout_lcd(int);

void main()
{

TRISA=0xFF;  // PORTA is input
TRISC=0xFF;  // PORTC is input
TRISB=0x00;
TRISD=0x00;
PORTB=0X00;
PORTD=0x00;

humidity=0;
temperature=0;
sound=0;
water=0;

acd_config();

TXSTA=0b00100100;  // Configure serialport
RCSTA=0b10010000;  // Configure serialport
SPBRG=25;  // Configure serialport

delay(50);
initialise_lcd();
delay(50);

command(0x01);
command(0x80);
display('A');
display('N');
display(' ');
display('I');
display('T');
display('I');
display('N');
display('E');
display('R');
display('A');
display('N');
display('T');
display(' ');
display('G');
display('S');
display('M');
display('-');
display('G');
display('P');
display('S');

command(0xc0);
display('A');
display('N');
display('D');
display(' ');
display('S');
display('E');
display('N');
display('S');
display('O');
display('R');
display('S');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

command(0x94);
display('I');
display('N');
display('T');
display('E');
display('G');
display('R');
display('A');
display('T');
display('I');
display('O');
display('N');
display(' ');
display('F');
display('O');
display('R');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

command(0xd4);
display('E');
display('N');
display('V');
display('I');
display('O');
display('R');
display('N');
display('A');
display('M');
display('E');
display('N');
display('T');
display('A');
display('L');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');
display(' ');

delay(5000);

command(0xd4);
display('E');
display('F');
display('F');
display('L');
display('U');
display('E');
display('N');
display('C');
display('E');
display(' ');
display('S');
display('C');
display('R');
display('E');
display('E');
display('N');
display('I');
display('N');
display('G');
display(' ');

delay(5000);

initialisemodem();
delay(1000);

command(0x01);
command(0x80);
display('D');
display('E');
display('L');

deleteallmsg();
delay(1000);

command(0x01);
command(0x80);
display('T');
display('S');
display('T');

sendtestmsg();
delay(1000);

command(0x01);

time=0;

while(1)
{

command(0x80);
display('T');
display(':');
acd_read(0);
temperature=adc_value;
temp=temperature;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display('.');
display(convert[digit5]);
display('C');
display(' ');
display(' ');
display(' ');
delay(30000);
command(0xC0);

display('H');
display(':');
acd_read(1);
humidity=adc_value;
temp=(humidity/10);
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('R');
display('H');
display(' ');
display(' ');

delay(30000);

command(0x01);
command(0x80);
display('W');
display(':');
acd_read(2);
water=adc_value/5;
temp=water;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('T');
display('D');
display('S');
display(' ');
display(' ');
delay(30000);
command(0xc0);
display('S');
display(':');
acd_read(4);
sound=adc_value;
temp=sound/10;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);
display('d');
display('B');
display(' ');
display(' ');

delay(30000);
command(0x01);
command(0x80);
display('A');
display(':');
acd_read(5);
air=adc_value;
temp=air;
hextobcd();
display(convert[digit2]);
display(convert[digit3]);
display(convert[digit4]);
display(convert[digit5]);


delay(1000000);
}
read_gps();

if(vd=='A')
{
command(0x01);
command(0x80);
display('L');
display('A');
display(':');
display(lat[0]);
display(lat[1]);
display(lat[2]);
display(lat[3]);
display(lat[4]);
display(lat[5]);
display(lat[6]);
display(lat[7]);
display(lat[8]);
display(lat[9]);
display(lat[10]);

command(0xc0);
display('L');
display('O');
display(':');
display(lon[0]);
display(lon[1]);
display(lon[2]);
display(lon[3]);
display(lon[4]);
display(lon[5]);
display(lon[6]);
display(lon[7]);
display(lon[8]);
display(lon[9]);
display(lon[10]);
display(lon[11]);

delay(5000);

}

else
{
command(0x01);
command(0x80);
display('I');
display('N');
display('V');
display('A');
display('L');
display('I');
display('D');
display(' ');
display('D');
display('A');
display('T');
display('A');
display(' ');
display(' ');
display(' ');
display(' ');

delay(1000);
}


if(sendb==0)
{
time=time+1;
if(time==5)
{
command(0x01);
command(0x80);
display('S');
display('E');
display('N');
display('D');
display('I');
display('N');
display('G');
display(' ');

delay(500);

time=0;
send_data();

}
}



}

void hextobcd()
{
countdata=temp;
countdata=(countdata/10000);
digit1=countdata;
countdata=(countdata*10000);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/1000);
digit2=countdata;
countdata=(countdata*1000);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/100);
digit3=countdata;
countdata=(countdata*100);
temp=(temp-countdata);

countdata=temp;
countdata=(countdata/10);
digit4=countdata;
countdata=(countdata*10);
temp=(temp-countdata);

digit5=temp;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void initialisemodem()
{
TXREG='A';			//change modem to text mode
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='F';
delay(5);
TXREG='=';
delay(5);
TXREG='1';
delay(5);
TXREG=enter;
delay(5);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void deleteallmsg()
{
TXREG='A';			//DELETE ALL MESSAGES
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='D';
delay(5);
TXREG='A';
delay(5);
TXREG='=';
delay(5);
TXREG=0x22;
delay(5);
TXREG='D';
delay(5);
TXREG='E';
delay(5);
TXREG='L';
delay(5);
TXREG=' ';
delay(5);
TXREG='A';
delay(5);
TXREG='L';
delay(5);
TXREG='L';
delay(5);
TXREG=0x22;
delay(5);

TXREG=enter;
delay(5);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
			
void sendtestmsg()
{
snumber();

TXREG='T';
delay(5);
TXREG='E';
delay(5);
TXREG='S';
delay(5);
TXREG='T';
delay(5);
TXREG=ctrlz;
delay(5);
}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void send_data()
{
snumber();

TXREG='D';
delay(5);
TXREG='A';
delay(5);
TXREG='T';
delay(5);
TXREG='A';
delay(5);
TXREG=':';
delay(5);

TXREG='L';
delay(5);
TXREG='A';
delay(5);
TXREG='T';
TXREG='=';
delay(5);

TXREG=(lat[0]);
delay(5);
TXREG=(lat[1]);
delay(5);
TXREG=(lat[2]);
delay(5);
TXREG=(lat[3]);
delay(5);
TXREG=(lat[4]);
delay(5);
TXREG=(lat[5]);
delay(5);
TXREG=(lat[6]);
delay(5);
TXREG=(lat[7]);
delay(5);
TXREG=(lat[8]);
delay(5);
TXREG=(lat[9]);
delay(5);
TXREG=(lat[10]);
delay(5);
TXREG=',';
delay(5);

TXREG='L';
delay(5);
TXREG='O';
delay(5);
TXREG='N';
delay(5);
TXREG='=';
delay(5);

TXREG=(lon[0]);
delay(5);
TXREG=(lon[1]);
delay(5);
TXREG=(lon[2]);
delay(5);
TXREG=(lon[3]);
delay(5);
TXREG=(lon[4]);
delay(5);
TXREG=(lon[5]);
delay(5);
TXREG=(lon[6]);
delay(5);
TXREG=(lon[7]);
delay(5);
TXREG=(lon[8]);
delay(5);
TXREG=(lon[9]);
delay(5);
TXREG=(lon[10]);
delay(5);
TXREG=(lon[11]);
delay(5);
TXREG=',';
delay(5);


TXREG='T';
delay(5);
TXREG='=';
delay(5);
temp=temperature;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG='.';
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='C';
delay(5);
TXREG=',';
delay(5);

TXREG='H';
delay(5);
TXREG='=';
delay(5);
temp=(humidity/10);
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='R';
delay(5);
TXREG='H';
delay(5);
TXREG=',';
delay(5);


TXREG='W';
delay(5);
TXREG='=';
delay(5);
temp=water;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='T';
delay(5);
TXREG='D';
delay(5);
TXREG='S';
delay(5);
TXREG=',';
delay(5);


TXREG='S';
delay(5);
TXREG='=';
delay(5);
temp=sound/10;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);
TXREG='d';
delay(5);
TXREG='B';
delay(5);
TXREG=',';
delay(5);


TXREG='A';
delay(5);
TXREG='=';
delay(5);
temp=air;
hextobcd();
TXREG=convert[digit2];
delay(5);
TXREG=convert[digit3];
delay(5);
TXREG=convert[digit4];
delay(5);
TXREG=convert[digit5];
delay(5);

TXREG=ctrlz;
delay(5);
}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
		

void snumber()
{
TXREG='A';			
delay(5);
TXREG='T';
delay(5);
TXREG='+';
delay(5);
TXREG='C';
delay(5);
TXREG='M';
delay(5);
TXREG='G';
delay(5);
TXREG='S';
delay(5);
TXREG='=';
delay(5);

TXREG=0x22;
delay(5);
TXREG='9';
delay(5);
TXREG='7';
delay(5);
TXREG='8';
delay(5);
TXREG='7';
delay(5);
TXREG='0';
delay(5);
TXREG='7';
delay(5);
TXREG='1';
delay(5);
TXREG='7';
delay(5);
TXREG='9';
delay(5);
TXREG='1';
delay(5);
TXREG=0x22;
delay(5);

TXREG=enter;
delay(5);

}			

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void read_gps()
{
if(OERR==1)
{
SREN=0;
temp=RCREG;
temp=RCREG;
CREN=0;
CREN=1;
SREN=1;
}

loop:

while(RCIF==0)
{
}
temp=RCREG;
if(temp!='$')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='G')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='P')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='R')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='M')
{
goto loop;
}
while(RCIF==0)
{
}
temp=RCREG;
if(temp!='C')
{
goto loop;
}

for(x=0;x<12;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<1;x++)			// valid transmission data
{
while(RCIF==0)
{
}
temp=RCREG;
vd=temp;
}

for(x=0;x<1;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<11;x++)			//collect latitude
{
while(RCIF==0)
{
}
temp=RCREG;
lat[x]=temp;
}

for(x=0;x<1;x++)			// leave data
{
while(RCIF==0)
{
}
temp=RCREG;
}

for(x=0;x<12;x++)			//collect longitude
{
while(RCIF==0)
{
}
temp=RCREG;
lon[x]=temp;
}

}


//////////////////////////////////////////////////////////////////////////////////////////
void acd_config()
{
  ADCON1=0b10000001;
  ADCON0=0b01000001;
  delay(1);
}

//////////////////////////////////////////////////////////////////////////////////////////
void acd_read(int channel)
{

if (channel==0)
{
ADCON0=0b01000001;
adc_data_accure();
} 
else if (channel==1)
{
ADCON0=0b01001001;
adc_data_accure();
} 
else if (channel==2)
{
ADCON0=0b01010001;
adc_data_accure();
} 
else if (channel==3)
{
ADCON0=0b01011001;
adc_data_accure();
} 
else if (channel==4)
{
ADCON0=0b01100001;
adc_data_accure();
} 
else if (channel==5)
{
ADCON0=0b01101001;
adc_data_accure();
} 
else if (channel==6)
{
ADCON0=0b01110001;
adc_data_accure();
} 
else
{
}
}
  
//////////////////////////////////////////////////////////////////////////////////////////
void adc_data_accure()
{
delay(1);
ADCON0=ADCON0|0b00000100;
delay(1);
adc_value=ADRESL; 		//collect ADRESL value 
adc_value+=(ADRESH<<8); //collect ADRESH value and add with ADRESL value 
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void delay(int time)
{
int i,j;
for(j=1;j<=time;j++)
{
for(i=0;i<=64;i++)
{
}
}
}

//////////////////////////////////////////////////////////////////////////////////////////
void initialise_lcd()

{
delay(5);
	command(0x30);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	delay(5);
	command(0x30);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	command(0x30);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	command(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	delay(1);
    command(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	delay(1);
	command(0x0F);		// Display On and Cursor Off
//	Delay(1);
	//lcdcmd(0x01);		// Clear display screen
	//Delay_ms(1);
	command(0x06);		// Increment cursor
	delay(1);
	command(0x80);		// Set cursor position to 1st line, 1st column
	delay(1);          //move cursor to space(0) 0,line 1(8)
}			

//////////////////////////////////////////////////////////////////////////////////////////			
void command(int lcddata)
{
delay(5);
rs=0;
rw=0;

lcdport=lcddata;
en=1;
en=0;

}
//////////////////////////////////////////////////////////////////////////////////////////
void display(int lcddata)
{
delay(5);
rs=1;
rw=0;
//lcdport=lcddata;
lcdport=lcddata;

en=1;
en=0;

}

//////////////////////////////////////////////////////////////////////////////////////////
/*void dout_lcd(int lcddata)
{
temp=lcddata;
temp=temp>>4;
temp=temp&0x0f;
lcdport=lcdport&0x07;
lcdport=lcdport|lcd[temp];

en=1;
en=0;

temp=lcddata;
temp=temp&0x0f;
lcdport=lcdport&0x07;
lcdport=lcdport|lcd[temp];

en=1;
en=0;

}

*/

actually the program is in lcd 4 bit mode,but i changed to lcd 8 bit mode
 


Code C - [expand]
1
void display(int);

expects int and you are sending char like 'a'. change it to

Code C - [expand]
1
void display(char);

in both prototype and definition.

Replace all display() calls by display_string() call


Code C - [expand]
1
2
3
4
5
6
void display_string(unsigned char *myString){
           while(*myString)display(*myString++);
        
}
 
display_string("Hello GSM");

 

hi brothers, then i am having a clarification regarding a project..

i want to do a project named'USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER USING PIC MICROCONTROLLER'.

description: in this i am using pic16f877a controller and compiling using hi tech c compiler.

ir sensor which is connected to controller used to take the input from a tv remote .these signals are then transmitted to PC for to implement these signals as cordless mouse in PC .i heard of a software 'PC remote'.i am having no idea about that .can you guide me in this.
 

hi brothers, then i am having a clarification regarding a project..

i want to do a project named'USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER USING PIC MICROCONTROLLER'.

description: in this i am using pic16f877a controller and compiling using hi tech c compiler.

ir sensor which is connected to controller used to take the input from a tv remote .these signals are then transmitted to PC for to implement these signals as cordless mouse in PC .i heard of a software 'PC remote'.i am having no idea about that .can you guide me in this.

It's very similar question as in the following thread...
https://www.edaboard.com/threads/300521/
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top