Setting Up Adc Ports


Closed Thread
Results 1 to 5 of 5
  1. #1
    GEEZER's Avatar
    GEEZER Guest

    Default Setting Up Adc Ports

    I switched from a 16F887a to 18F4610. I have everything running including a serial output controlling a dual pot.

    My problem is always those darn adc ports. I need to set up and read analog on porta 0 -7. I get strange readings or nothing at all. I had it working fine on the 877A, but can't make the transition on the 4610.

    A little sample code would be great. I admit I don't grasp the adcon settings, any simplified explanation would help, with examples. Maybe I can get my mind around these adcon settings.

    Thanks,

    Geezer

  2. #2
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Post

    Hey Geezer -
    One example that really helped me learn what to look for and how to read the data sheet for the A/D modules is HERE. I realize it's not the same micro you're working with, but Bruce does point out some very important steps on how to set up the A/D module. I haven't worked with the Pic 18x's yet, so I'm not even going to try to code anything without testing it. All I can say, is get to know the data sheet. Just by taking a quick look, it says
    The module has five registers:
    • A/D Result High Register (ADRESH)
    • A/D Result Low Register (ADRESL)
    • A/D Control Register 0 (ADCON0)
    • A/D Control Register 1 (ADCON1)
    • A/D Control Register 2 (ADCON2)
    ADCON0 controls
    • turning on/off the ADC module
    • starting the conversion
    • indicating which channel to read
    ADCON1
    • voltage reference configurations
    • AD port configuration bits
    ADCON2 contains
    • the result format
    • acquistion time selection
    • the conversion clock selection
    ADRESH & ADRESL, of course hold the result from the A/D conversion. Chances are you'll have to do something with each one of these registers, depending on how you want to execute the A/D conversion. Sorry I don't have a cut & paste example for you, but maybe I've helped steer you in the right direction in figuring out the ADC module.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    If I may put my 2 cents in here, I use A/D converters all the time. However, I don't "set up" anything except tell the device to turn all A/D ports to digital on boot. On 12F675 I use ANSEL = 0. On 16C72A, 16F72 and 16F818, I use ADCON1 = 7. Then, I simply use the ADCIN command and it works every time for a 0-255 reading. ADCIN 0, X will read ANA0 and put value into BYTE variable X. And if Anyone here knows why I shouldn't do it this way, please let me know. Thank you. - Peter

  4. #4
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for the input guys. Peter, I am glad it is working out so easily for you.

    I have it running now. I just ignored ADCON0 and set ADCON1 and 2. I think I know what i did to turn on 4 of the ports i need right now. We'll see how smart i am when i need to turn on the next 4.

    Thanks again, I get a lot of help and good ideas from the forum.

    The Geezer

  5. #5
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by peterdeco1
    if Anyone here knows why I shouldn't do it this way, please let me know. Thank you. - Peter
    More than one way to skin a cat. Sure the ADCIN command can be used and probably work just fine, and get him up and going quickly. I like using the ADC registers directly to understand what's all involved. Which from Geezer's post, I was under the impression he was after this as well. Other people also do this for speed and efficiency. Instead of telling someone to RTFM... I try to point them in the direction of examples and where to look in the manual to learn what they are after. Just a personal preference. Glad you got your project going Geezer... and hopefully you have a better understanding of the ADC module.

Similar Threads

  1. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 15:01
  2. Setting I/O ports on 16f629
    By Optech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2008, 22:51
  3. Setting Address via ADC
    By breesy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th October 2007, 15:33
  4. Setting up ADC....
    By robertmark68 in forum General
    Replies: 1
    Last Post: - 11th August 2006, 19:08
  5. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 17:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts