16F88 + 2 Analog inputs


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi tenaja,

    Actually i use always the name given in the pinout definition:

    Si var PORTA.0 'input1
    Li var PORTA.1 'input2

    My code has changed alot after some experiments and some reading.

    Unfortunately changing to ADCin 0 or ADCin Si does not change the readings.

    Still not working

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Using an alias to a port + pin is fine for some operations, but what tenaja told you is 100% correct. You cannot use anything except ADCIN 0,VAR - or ADCIN 1,VAR, etc.

    The 0,1,2,3,4, etc immediately after the ADCIN command is a constant. Not an alias to a PORT + PIN. This should be fairly clear by simply reading the manual, and looking at the example provided - or searching this forum for ADCIN examples.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    You are still using the incorrect syntax. You need to use numbers 0 through 6 (since your pic has 7 channels), or symbols representing those numbers, not PORT numbers. If it works with a Portx, then it's just coincidence and this bad practice will come back to bite you. You could easily be reading some pin other than the one you want. READ THE MANUAL.

    Second, I just read about your resistor connections:
    Pic has only 3 connections ( output to RS232 and 2 analog inputs ). I have a 330K resistor from VDD to AN0 and a 47K resistor from VDD to AN1.

    Measuring voltage on these 2 pins i have AN0 = 1.19V and AN1=4.82V
    If my math is correct i should have readings like AN0= 244 and AN1=986 ( 10Bits calculation ).
    This is the reason you are getting high values instead of low values. Either you misrepresented your circuit, or you do not understand resistor networks.

    For starters, the datasheet says you need 10k max to ground--see section 12.1 of the datasheet--it's in BOLD in the first paragraph! You don't mention any R's to ground, and the values you do mention are way out of spec. If that's he case & you don't have a resistor going to ground, then you should theoretically have VDD volts at both a/d ports--and that explains your readings near 1024. If you do have an R to ground in a similar high K range, you could easily be getting an unreliable value due to the high impedance.

    Toss in those extra two resistors, fix your channel numbers, and you are good to go.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi Tenaja and Bruce

    Thanks for your support.

    About the pin calling its noted

    But Tenaja was also right about the input impedance.

    The circuit was missing the pulldown resistors.
    I checked the datasheet and it's confusing for me that in bold it states the max impedance for analog sources is 2.5K and at the bottom square states the max impedance for analog sources is 10K. Which should we follow ?

  5. #5
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Page 117 it states 10k in two places; text and notes. Page 190 says 2.5 with a NOTE, that says 10k is allowable with an increased acquisition time. That basically means extra time to charge the sampling cap. If you plug your numbers into equation 12-1 on pg. 117 you will get the appropriate time required. IIRC, the fastest it can go is around 30-35kHz, so with a 10k R, you'll have to slow it down to be reliable.

    However, if you don't need 10bit accuracy, it probably doesn't matter.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Got it

    Thanks Tenaja

  7. #7
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Thanks

    I had been struggling with the AD in the 16F88 recently and the answers you gave straightened me out. There's only so much documentation one person can digest and it is really wonderful to have this forum where we can learn from each other.

    Thanks Tenaja
    "Do or do not, there is no try" Yoda

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