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


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2009
    Posts
    653

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

    Anyone seen such a thing before.... on the face of it, my ADC seems to be reading fine...if I put a pot between VCC & Gnd, I see the wiper reading increment as expected up to 255 ....but then when I turn it down fully, I don't see readings below 008...even if I short the ADC pin to the PIC's ground connection (ie to eliminate the pot as being the source of the problem).

    i've tried other ADC pins....the same.

    I'm at a loss as to what might be going on here?

  2. #2
    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)

    by any chance is there a multiplexed comparator on this pin?!?

    Are you sure the Vref is set to internal?
    Steve

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

  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)

    There is (PIN 6 12LF1822) , but I've turned the compartators off...

    Code:
    @ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
    @ __CONFIG _CONFIG2, _LVP_OFF
    DEFINE  OSC 8 
      '
    INCLUDE "DT_INTS-14.bas"     ' 
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
     
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 16  ' 115200 Baud @ 8MHz, 2.12%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
     
    APFCON.2 = 1          ' PUT HSEROUT ON PIN 3 (ra4)
    APFCON.0 = 0          ' PUT CCP1 onto RA2 Pin5
     
    Osccon = %01110010     'sets the internal oscillator to 8Mhz
     
    DEFINE ADC_BITS  8     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 1     ' ADC clock source  (Fosc/8)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds 
     
    CM1CON0 = 0   ' COMPARATORS OFF
    CM1CON1 = 0   ' COMPARATORS OFF
    ADCON0 = %00000010     'AN0 Enabled (Pin 5) + ADC On
    ADCON1 = %00000000     'set ADC +ve ref to internal VREF (00 is VCC)
    'FVRCON = %11000001     ' turn fixed internal voltage reference on & set it to 4.096V (last two bits set the voltage ...01 =1.024V,10=2.048
     
    OPTION_REG = 0   'WEAK PULLUPS ENABLED
    WPUA.3 = 1    ' RA3 pin 4 enabled (SW1)
    IOCAN.3 = 1    'interrupt on -ve going edge (SW1
     
    cpscon0 = 0             'turn off capacititve touch
     
    'HPWM SETTINGS (MANUAL SETTING OF THE REGISTERS VS THE PICBASIC HPWM COMMAND)
    CCP1CON    = %00001100   ' Turn HPWM on on CCP1
    TRISA.2 =1               ' Disable the CCP2 pin output driver by setting the bit
    CCPR1L.6 = 0             'I'm only using 8 bit PWM so clear the top two bits
    CCPR1L.7 = 0             'I'm only using 8 bit PWM so clear the top two bits
    PR2= 63                  'THIS SETS THE PWM PERIOD (FREQUENCY) to 15.625KHZ @4MHZ (I hope - not scoped it!)
    T2CON = %00000100        'TIMER2 ON 1:1 PRESCALER 1:1 POSTSCALER
    TRISA.2 = 0              'Enable the CCP2 pin output driver by setting the bit
     
    OPAMP VAR PortA.5
    SW1 VAR PortA.3
     
    latest_sample var byte
     
    TEST1:
    adcin 1, latest_sample
    hserout [dec latest_sample,13,10]
    PAUSE 200
    GOTO TEST1
    ADC +Vref is set to be VCC.

    (Not sure what's going with the formatting - when I copied/pasted there were heaps of line breaks in my code - to make it easier on the eye!)
    Last edited by HankMcSpank; - 19th May 2011 at 18:40.

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

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

    Hi Hank,

    I had a ton of trouble with the A/D with these chips. Turns out the Erata points at a big problem. http://ww1.microchip.com/downloads/e...Doc/80502C.pdf

    You can't use the a/d as you normally would. I had to write a few lines of code to grab the a/d data (not using ADCIN), that included a pause to wait long enough for the a/d to complete. That is because the chip does not give valid data for the done bit.

    In my opinion, this makes the chip kind of broken! But there are some cool aspects of the chip that make it nice to use in some projects. I wish they would tell you this in the data sheet, not just the erata. Maybe right under the analog to digital section of the data sheet, say something like "Oh by the way, you can't use the a/d like we said you could ..... and not like the way you use it in any of our other products". But maybe that's just me. I suppose the marketing department sent that back for editing.

    Walter
    Last edited by ScaleRobotics; - 19th May 2011 at 18:59.

  5. #5
    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.

  6. #6
    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)

    Quote Originally Posted by scalerobotics View Post
    Hi Hank,

    I had a ton of trouble with the A/D with these chips. Turns out the Erata points at a big problem. http://ww1.microchip.com/downloads/e...Doc/80502C.pdf

    You can't use the a/d as you normally would. I had to write a few lines of code to grab the a/d data (not using ADCIN), that included a pause to wait long enough for the a/d to complete. That is because the chip does not give valid data for the done bit.
    HHHHA,, missed that Errata... however they also suggest what I said, using the Frc clock. Have you tried it?

    I never use ADCIN so adding the SLEEP thing would be easy thing to do.
    Steve

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

  7. #7
    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 19:20.

  8. #8
    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 21:00.

  9. #9
    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.

  10. #10
    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: 367
Size:  66.8 KB
    DT

  11. #11
    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 22:31.

  12. #12
    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 : 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