How to make adcin stable?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    You can connect Vref to Vdd, but it is easier just to set ADCON1 bits 5&4 to "0" which connects Vref to Vdd internally.

    Also, READ YOUR DATASHEET. Here is a cut and paste directly from the A/D section of the 18F8722 datasheet:

    The
    maximum recommended impedance for analog
    sources is 2.5 kΩ.


    Other chips have similar recommendations.

    Your 350K is WAAAAAY too high! If you really need a 350K pull-up, you will
    have to buffer the analog signal with an op-amp to get accurate readings.


    If you just want to sense the presence of an object, you would be better off using a digital input, and connecting the collector of your phototransistor to 5V through a 10K or 22K resistor.
    Charles Linquist

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default

    I would suggest to use an opamp as a unity gain buffer befor feeding the ADC of the PIC.

    As Charles stated 350K is too high for the ADC to work reliable.

    Also to be sure that the PIC is working OK, use a trimmer in the place of the phototransistor and check the results. If they are stable and seem expected then you can be sure that PIC is OK. Of course it would be a very good idea to average the samples. Have a look at Darrels averaging routine at his site:

    http://www.pbpgroup.com/modules/wfse...hp?articleid=7

    Ioannis

  3. #3
    Join Date
    Jan 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default 10 bit results

    Can anyone tell me why I am getting 16 bit results from this code? I expect at 5 volts in I should see 1023 but I see 65535.I am using a 16f616.



    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    TRISA = 255 ' Set PORTA to all input
    ADCON1 = 2 ' PORTA is analog
    ADCIN 0, A0 ' PORTA.0 PIN 13

  4. #4
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    change your ADCON1 =2 with

    ADCON1=%10000010

  5. #5
    Join Date
    Jan 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default 10 bit results

    Thank you for your reply. I made that change, I am now back to 8 bit results. I would like to have 10 bit results.

    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    your variable A0 by ADCIN must be defined as word and no as byte

  7. #7
    Join Date
    Jan 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Thank you so much for your help!

    This is all of the code,

    A0 VAR WORD
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    TRISA = 255 ' Set PORTA to all input
    'ADCON1 = 2 ' This gives me 16 bit results
    ADCON1=%10000010 'This gives me 8 bit results
    ADCIN 0, A0 ' PORTA.0 PIN 13
    SEROUT PORTC.5,6,[" A0 = ",#A0,10]

Similar Threads

  1. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 21:27
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 18:25
  3. ADCIN problems with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 26th July 2007, 12:38
  4. How come they make electronics hard as poss
    By George in forum Off Topic
    Replies: 9
    Last Post: - 14th July 2007, 00:54
  5. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 08:46

Members who have read this thread : 0

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