ADCON settings PIC18F4550

Discussion in 'Embedded Systems and Microcontrollers' started by lostinspace73, May 20, 2012.

  1. lostinspace73

    Thread Starter New Member

    Jan 21, 2011
    6
    0
    Can anyone explain to me what the following ADCON settings represent? I understand bits and pieces but the harder I try to wrap my head around the whole picture, the more confused I get:

    ADCON0 = 0x00000101;
    ADCON1 = 0b00001011;
    ADCON2 = 0b10000001;

    A bit by bit explanation would be ideal however any assistance would be extremely helpful as my textbook does not clearly define these registers (ADCON2 is not even in the book).
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    They are clearly explained in the datasheet, which you can get from the Microchip website.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    ADCON0 does 3 things: turns the A2D hardware on, flags when a conversion is complete, and picks which channel is going to be converted.

    ADCON1 picks the reference voltage sources (both low and high) for the end points, and picks which group of pins will be used for analog

    ADCON2 picks if the result is left justified (useful for just using the upper 8 bits of the result) or right justified (useful when using the entire 10 bits), how long a delay between saying GO and the start of an acquisition, and the clock source for the A2D hardware.

    Here's where the control bits appear in the code:
    Code ( (Unknown Language)):
    1.  
    2. ADCON0 = 0x00000101;
    3. //         --0001--    select AN1
    4. //         ------01     GO/DONE (it's done)  
    5. //         -------1     hardware main screen on
    6.  
    7. ADCON1 = 0b00001011;
    8. //         --0-----     use Vss as a ref
    9. //         ---0----     use Vdd as a ref
    10. //         ----1011     AN0-AN4 enabled
    11.  
    12.  
    13. ADCON2 = 0b10000001;
    14. //         1-------     right justified result
    15. //         --000---     0 TAD delay or no delay before reading
    16. //         -----001     A2C clock is Fosc/8
    17.  
    BTW, that's typically how I document my code in my code so you can see how and why each bit is set, except I'll typically also tag the page number of where the register description is.

    Additionally, the PIC18F4550 was an awesome device a decade ago when it was first introduced. There are much better parts available today for the same price.
     
    Last edited: May 20, 2012
    lostinspace73 likes this.
  4. lostinspace73

    Thread Starter New Member

    Jan 21, 2011
    6
    0
    VERY helpful. Thank you, sir.
     
  5. Michael Dockery

    New Member

    Sep 1, 2015
    2
    0

    which better parts would you recommend?
     
  6. Michael Dockery

    New Member

    Sep 1, 2015
    2
    0
    Which better parts would you recommend?
     
  7. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi,
    This thread is from 2011. It is old. The TS has moved on. Please start your own thread, where you explain what you want to do, or what you have problems with.

    Oh, and welcome to AAC. Hope you like it here. :)
     
    ErnieM likes this.
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,548
    2,373
    P18F23k22 P18f46K22?
    Max.
     
Loading...