Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

ADC Not Working (Using PIC 16F877)

Status
Not open for further replies.

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
Hello,

Ive read the data sheet of PIC 16F877 and coded my microcontroller accordingly, but it does not appear to work. I am using sourceboost as my compliler.

Here is my code:

Code:
#include <system.h>
unsigned char adcconv(void);
unsigned char inbyte;
void config(void);

void main(void)
{
	config();
	do{
		portb=adcconv();
		
	}while(1);
	
}

unsigned char adcconv(void)
{
		
	adcon0.GO=1;
	
	do{
		
	}while(adcon0.GO==1);
	
	return(adresl);

}

void config(void)
{
	status |=0x20;
	adcon0=0x0c1;
	adcon1=0x01;
	trisa=0xff;
	trisb=0x00;
	status &=0xdf;
}
ive set the registers accordingly, and Ive connected pin RA3 to Vref and RA0 is my analog input.

no matter what I do, the output value does not change and the adresl returned value is always 0.

Can anyone help me out here? Thank you
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
This line wont help a lot?

adcon0=0x0c1;

it selects channel 1 and turns the A/D off. (Maybe)

I think adcon1 should be 0x81 to right justify the result.
 
Last edited:

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
This line wont help a lot?

adcon0=0x0c1;

it selects channel 1 and turns the A/D off.
its c1, so it will set the adcon0 to 11000001.. which will select internal oscilator, choose 000 for channel selection, and turn A/D on..

correct me if im wrong please
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
I think adcon1 should be 0x81 to right justify the result.
 

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
i tried 0x81 as well, but that did not create any difference :( was still getting 0 as returned value
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
I don't think you need set and clear the STATUS bits, the compiler should take care of that.

Have you tried MPlab Sim and step through the code, use the watch window to look at the regs.
 

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
yeah, i know, i was just trying it out in hopes that it will work..at first the code was without the status registers, when it did not work i added them in =/
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top