0

I've made a configuration file regarding the registers:

void ADC_Init()
{
ADCON1bits.ADCS2 = 0;
ADCON0bits.ADCS1 = 1;
ADCON0bits.ADCS0 = 0;
//selection of a channel
ADCON0bits.CHS0=0;
ADCON0bits.CHS1=0;
ADCON0bits.CHS2=0;
//result format selection
ADCON1bits.ADFM=0; //right justify
//port configuration
ADCON1bits.PCFG0=0;
ADCON1bits.PCFG1=0;
ADCON1bits.PCFG2=0;
ADCON1bits.PCFG3=0;
//set status sit
ADCON0bits.GO_DONE=1;
//switch on ADC
ADCON0bits.ADON=1;
}

Now how do I get the int reading coming from the input?

1
  • What is written in the user manual of the processor, regarding the reading of values after initialization?
    – virolino
    Commented Jun 24, 2019 at 5:24

1 Answer 1

1

Wait for the ADC to be ready and then read the result.

while (ADCONbits.GO_DONE);     //wait until conversion is ready
result = (((uint16_t)(ADRESH) << 8)) | ADRESL;

But best thing you could do is to write a function e.g. int_16_t readADC(int16_t channel) where you:
- select the channel
- start the ADC
- wait until its ready
- then return the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.