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.

pic16f877a multiple ADC problems..

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
I have to sense two analogue voltages with the help of PIC16F877A

But the problem is that my Second Channel of ADC is not working....
Its value is not changing and remains same as that for the first conversion..

Here is my code

Code:
	ADCON0 = 0x81;
	ADCON1 = 0xC4;
        while(1)
	{
		__delay_us(100);
		ADCON0bits.GO = 1; //Start Conversion
		while(ADCON0bits.GO == 1);	//Wait Here for End of COnversion
		adc_data = ADRESH & 0x00FF;
		adc_data = adc_data<<8;
		adc_data = adc_data | ADRESL;
		
		ADCON0 = 0x80;	//A/D Feature is Powered-OFF
		/************************************************
		Time to Start Second Timer located at AN1
		**************************************************/
		__delay_ms(20);
		ADCON0 = 0x89;
		ADCON0bits.GO = 1;	//Start Conversion
		while(ADCON0bits.GO == 1);	//Wait Here for the End of Conversion
		adc_phase_data = ADRESH & 0x00FF;
		adc_phase_data = adc_phase_data<<8;
		adc_phase_data = adc_phase_data | ADRESL;
		ADCON0 = 0x80;	//A/D Feature is Powered-OFF

		/*****************************************
		SWITCH BACK to First Analog Channel
		******************************************/
		ADCON0 = 0x81;
		__delay_ms(20);
	}

Can any one help me regarding this...
 

hi
1- in your code there is not any delay for charging S/H capacitor on second channel.
i think that you inserted "__delay_ms(20);" for this, but you should
insert delay after selecting a channel (not before it).
2- don't set ADON bit and GO/DONE bit in same instruction. first set ADON and then
set GO/DONE (after some time to charging S/H).
3- there is no need to turn off AD to changing channels, you can change channel while
the AD is on.
4- 20ms delay is not needed for charging S/H capacitor.
5- try this code:


ADCON0 = 0x81;
ADCON1 = 0xC4;
while(1)
{
//__delay_us(100);
ADCON0bits.GO = 1; //Start Conversion
while(ADCON0bits.GO == 1); //Wait Here for End of COnversion
adc_data = ADRESH & 0x00FF;
adc_data = adc_data<<8;
adc_data = adc_data | ADRESL;

//ADCON0 = 0x80; //A/D Feature is Powered-OFF
/************************************************
Time to Start Second Timer located at AN1
**************************************************/
ADCON0 = 0x89;
__delay_ms(20);

ADCON0bits.GO = 1; //Start Conversion
while(ADCON0bits.GO == 1); //Wait Here for the End of Conversion
adc_phase_data = ADRESH & 0x00FF;
adc_phase_data = adc_phase_data<<8;
adc_phase_data = adc_phase_data | ADRESL;
//ADCON0 = 0x80; //A/D Feature is Powered-OFF

/*****************************************
SWITCH BACK to First Analog Channel
******************************************/
ADCON0 = 0x81;
__delay_ms(20);
}
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top