A/D versus Digital I/O


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    dallennn's Avatar
    dallennn Guest

    Question A/D versus Digital I/O

    I am using PBPro programming the 16F876 for both analog and digital use. I see that the command ADCON1 needs to be set for these purposes. I need 1 A/D channel and as much digital I/O as I can get. Is there a way - or how do I set up the ADCON1 command to enable A01 as the analog input and A02-A05 as digital?
    Do I also have to set up any other command?

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,182

    Default

    Take a look at this post first.
    http://www.picbasic.co.uk/forum/showthread.php?t=4880

    And try to come up with a register setting and then post it here.

    We can then check if you made it right or wrong.

    So you can understand how to make it.





    ---------------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3

    Default

    Hi Dallennn & Sayzer. I use the ADC's on 16F872 frequently. I just make them all digital, then declare the input. When you use the adcin command, it automatically converts it to a byte size analog input. Example using ra0 as ADC input:

    trisa = %00000001 'ra0 input
    adcon1 = 7 'all inputs digital
    x var byte 'place to put the ADC reading

    start:
    ADCIN 0,X 'read adc value & put into x

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,182

    Default

    Hi peterdeco1,

    Never tried that before.

    Sounds a quick jump to actual reading procedure.

    Since you say you have done it and it works, I now learn something new.

    Thanks for the info.


    ----------------------
    Last edited by sayzer; - 31st October 2006 at 14:49.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    dallennn's Avatar
    dallennn Guest

    Smile It works!

    Hi peterdoco1 and Sayzer,

    Peterdoco1, I first tried your solution and it worked! And that is:
    trisa = %00000001
    adcon1 = %00000111

    Sayzer, I then looked at and tried your solution and it worked! Your solution was to look at the register table for adcon1 and find the the values for that which I wished to do which is: ra0 = analog and ra1-5 as digital. This gave me a value of:
    trisa = %00000001
    adcon1 = %00001110
    Is that what you would have used?
    I did have one small problem getting ra4 led to turn on until I remembered that ra4 is open drain.

    dallennn

  6. #6

    Default

    Hi Dallennn. You said ...ra0 = analog and ra1-5 as digital. This gave me a value of:
    trisa = %00000001
    adcon1 = %00001110

    As I mentioned previously, I always let the software do the work for me and will work for word variables too. But one thing I see in your post above is the trisa register is set for ra0 input, the rest all outputs.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,182

    Default

    dallennn,

    TRISA = %00000001 will set RA0 as an input and all others as output pin as you know. So this is ok.

    ADCON1= %00001110 will set RA0 as an analog pin and all others as digital pin. This is also as you needed. So it is ok.

    Thus, so far you have an analog input pin at RA0 and all others as digital output pins.

    One thing to remember is Bit7 anf Bit6 of ADCON1. Depending on your ADC resoultion, you need to set Bit7.

    Another thing is Bit6 and this will be set by your DEFINE directive automatically.


    -----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    dallennn's Avatar
    dallennn Guest

    Smile I think I have it!

    Hi peterdoco1 and Sayzer,

    Sayzer, I know to set ADCON1 bit 7 for left or right justify. All I needed was 8 bit resolution so I set the bit to 0. I couldn't find anything on bit 6 but.........
    I think I now have enough information to be dangerous.
    Thanks for both of your help.
    Dallennn

Similar Threads

  1. Digital Out on an A/D pin safe ?
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st January 2009, 23:48
  2. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 03:16
  3. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 15:39
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 19:57
  5. digital I/O
    By igeorge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th December 2005, 01:56

Posting Permissions

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