A little confusion about ADC

Thread Starter


Joined Apr 2, 2009
I always use ADC with internal reference, and use ADC_Read() function.
I looked at the mikroC help and it shows this.

In the Note: it says "This function doesn't work with the external voltage reference source, only with the internal voltage reference."

In my current project I set the Vref as external. GND and +5V applied to Vref Pin.

  ADCON1.ADFM = 1; // A/D Right Justified.
  ADCON1.VCFG1 = 1; // External Vref-.
  ADCON1.VCFG0 = 1; // External Vref+.
I am confused a bit.
Can any one explain this. Please. :(

Another question.
Somewhere I read ;
by using "ADC_Read" , The ADC is first initialized and then Pin is Read.
by using "ADC_Get_Sample" , The ADC is not initialized but just Read.So here I must use "ADC_Init(); " in main just like" LCD_Init();"
Is my understanding correct ?
And the time taken is smaller in "ADC_Get_Sample" than "ADC_Read" as the ADC is initialized before hand in "Main".

Thread Starter


Joined Apr 2, 2009
Beginners are at the mercy of the library developers :(
And I am not that good to write my own hardware drivers.


Joined Mar 2, 2015
When you write C, unless you write your own hardware drivers, you are at the mercy of the library developers.
Beginners are at the mercy of the library developers :(
And library developers sometimes (often?) don't put much thought into the variety of different ways people might want-- or might need-- to operate the hardware. So you end up getting stuck with a very inflexible "virtual interface" to the hardware which, although it might make it easier to operate the hardware in some logically straightforward, easy-to-understand fashion, nevertheless severely limits your ability to do anything creative. Like here.

Situations like this are the reason I much prefer working in assembly language. JMHO...


Joined Jun 22, 2012
Usually in pics, you set the 'ADCON_GO' bit, this starts the A/D, and then loop a bit test on it to see when it clears, the value will be put into the respective A/D registers..


Joined Dec 2, 2013
Here is a simple working example but you have to adjust it for your pic. (like pir1bits.adif in some pic adif is enough)

//----------------------- in interrupt routine --------------------------------

if (PIR1bits.ADIF)
PIR1bits.ADIF = 0; // Clear A/D conversion complete interrupt flag
Delay1KTCYx(5); // Delay for 5000 instruction cycles
Vbatt=(float)(ADRESH*256 + ADRESL);
//------------------- setup ------------------------------

ADCON0bits.ADON = On; // 1 Turn A/D on
ADCON1bits.VCFG1 = 0; // VREF- = AVSS
ADCON1bits.VCFG0 = 0; // VREG+ = AVDD
ADCON1bits.PCFG3 = 1; // 1Select 1 Analog channel, AN0
ADIE=1; // set int
GIE=1; // set all ints

// ==== main loop ============

ADCON0bits.GO = 1; // get value start ad

if (Vbatt<10)
Vbatt=Vbatt*0.0357; // real value compensated with factor to comply with input voltage