My 12lf1822 ADC won't read zero (lowest reading is 008)


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    Weird, I would try something

    ANSEL is not set, set it so the unused Analog pin will be digital

    Increase your ADC Sampling Time, set Fosc to Frc.

    This should do the trick.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    My apologies, I stripped out some linesfrom my program (ie a list of what I have attached to all the pins), to condense the code & make it eaasier to read , it seems I got carried away with the delete key when posting

    Code:
    TRISA = %11001010    'RA2 hpwm out therefore output needed
    ANSELA =%00000010    'SIG in (RA1) NEED TO BE ANALOGUE.
    ....that above bit missing from my original code.

    I'll try increasing the sampling time (but not sure why it would be 'signal level' sensitive....ie above a few millivolts right up to VCC, the ADC reads fine)

    Walter....oh dear, not what I wanted to hear (re your problems). I did read the errata sheet, but that seems to relate more to ADC not completing (hanging?) under certain circumstances.... whereas this appears to be working as it should my readings are totally fine above 008 upto 255 ....just can't get under 008...even short to the PIC's ground pin.

    I've only recently progressed from using ADCIN ...I'm just using it here cos it's quick!

    Edit: just tried setting the Fosc to Frc ....hmmm, I won one bit back ...my ADC now reads between 007 & 255!
    Last edited by HankMcSpank; - 19th May 2011 at 18:20.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    well, I got to the bottom of it...something whacky going on here!

    It's something to do with the way I'm setting the weak pullup register....

    Firstly, I noticed that when I disabled weak pullups (I just took a flier!)

    Code:
    OPTION_REG.7 = 1 ' disable weak pullups
    My ADC started reading down to zero as it should!

    Sure enough when I enabled weak pullups again, the problem returned.

    But this is where I’m obviously doing something wrong, this way actually works…

    (I want weak pullups of RA3)
    Code:
    WPUA  = %00001000 
    IOCAN = %00001000 
    …ie even with weak pullups enabled my ADC reads down to zero.

    But if I do this….

    Code:
    WPUA.3 = 1
    IOCAN.3 = 1
    My ADC won’t read down below 008 again!

    So to get ADC reading down to zero *with* weak pullups enabled on a 12LF1822, it must be set like this....

    Code:
    OPTION_REG.7 = 0
    WPUA  = %00001000 
    IOCAN = %00001000 
    Not sure if it makes any difference but my weak pullup is on the MCLR pin.

    Anyway, I'm happy - it's sorted!
    Last edited by HankMcSpank; - 19th May 2011 at 20:00.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    That's interesting. I also thought the WeakPullups could do something but never had this problem before. Nice finding.

    So I guess doing the ADC while sleeping would also have do the trick.

    Since it's working... don't fix it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    Nothing whacky there.

    The WPUA register defaults to %00111111 on power-up.

    If you do WPUA.3 = 1
    nothing changes, because that bit is already a 1.
    You have to disable pull-ups on the pins you don't want pulled-up.

    The numbers over each bit show the POR/BOR defaults.
    Name:  1822_WPUA.JPG
Views: 648
Size:  66.8 KB
    DT

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    For once you' re wrong (& I've got you on a minor technicality!) - there was something whacky - ME!

    I guess (me aside) the other whacky thing was even with weak pullups enabled ...my ADC pin still functioned.....albeit only down to a reading of 008 (whenever I've set an ADC pin wrong prior...I've had very "something oviously wrong with my config" type results ...this one was more obscure!)

    Anyway, apologies for the schoolboy error....
    Last edited by HankMcSpank; - 19th May 2011 at 21:31.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: My 12lf1822 ADC won't read zero (lowest reading is 008)

    must do mistake from time to time... this is the best way to learn
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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