A little confusion about ADC

Discussion in 'Programmer's Corner' started by R!f@@, Oct 17, 2016.

  1. R!f@@

    Thread Starter AAC Fanatic!

    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.

    Code (C):
    1.   ADCON1.ADFM = 1; // A/D Right Justified.
    2.   ADCON1.VCFG1 = 1; // External Vref-.
    3.   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".
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    When you write C, unless you write your own hardware drivers, you are at the mercy of the library developers.
    OBW0549 likes this.
  3. R!f@@

    Thread Starter AAC Fanatic!

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

    Well-Known Member

    Mar 2, 2015
    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...
    joeyd999 likes this.
  5. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    So any thoughts on my problem guys ?
  6. Dodgydave

    Distinguished Member

    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..