Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem in ADC code

Status
Not open for further replies.

Jyothi@Pic

New Member
Hi,

Below is the ADC code I have made all the configuraion but when i enter debug mode and run i am not getting the ADC result Kindly tell me if there is any mistake in the code.



Code:
//#include<p18f4620.h>
//#include<adc.h>


#include <p18F4620.h>
#include <adc.h>
#include <stdlib.h>
#include <delays.h>

int result;

void ADC_init(void);
void ADC_conv(void);

void main( void )
{

    //OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST &  ADC_1ANA , ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS );
	ADC_init();
    while(1)
    {
  		Delay10TCYx(5);                           // Delay for 50TCY
		//ConvertADC();                           // Start conversion
		ADCON0bits.ADON=1;
		//while( BusyADC() );                     // Wait for completion
		while(ADCON0bits.GO==1);
		//result = ReadADC();                     // Read result
		//CloseADC();                             // Disable A/D converter
	}
}



void ADC_init(void)
{

	ADCON0bits.CHS3=0; ADCON0bits.CHS2=0; ADCON0bits.CHS1=0; ADCON0bits.CHS0=0;//ADC channel setting AN0
    ADCON1bits.VCFG1=0; ADCON1bits.VCFG0=0;                                    //Vref+=Vdd    Vref-=Vss
    ADCON1bits.PCFG3=1; ADCON1bits.PCFG2=1; ADCON1bits.PCFG1=1; ADCON1bits.PCFG0=0;//A/D Port Configuration Control bits
    ADCON2bits.ADFM=1;                                           //right justified
    ADCON2bits.ACQT2=1; ADCON2bits.ACQT1=1; ADCON2bits.ACQT0=0;  //Aqusition time settings
    ADCON2bits.ADCS2=1; ADCON2bits.ADCS1=0; ADCON2bits.ADCS0=1;  //A/D Conversion Clock Select bits

}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top