Help with ADCin


Closed Thread
Results 1 to 13 of 13

Thread: Help with ADCin

  1. #1
    Join Date
    May 2011
    Posts
    7

    Default Help with ADCin

    Hello, my name is Ron and I'm new to the forum, but not new to PICs and or PBP.

    I'm currently using PBP 2.50c, bought my first copy of PBP back in '99.

    My current project is a constant current dummy load. I'm having some problems with the ADCin command and wondering if someone here could help.

    I'm ussing a PIC16F873A running at 20 Mhz, the Vdd is 5.013 Vdc.

    Trying to read a voltage between 0 and 5 Vdc at AN0.

    I would expect to see an ADC count of 0 at 0.00 Vdc, 512 at 2.500 Vdc, and 1023 at 5.000 Vdc.

    Here is the problem.... the ADC count is 0 from 0.000 to 0.063 Vdc, and at 2.500 Vdc it display 505, and 1023 at 5.00 Vdc.

    Any takers on what I'm doing wrong?

    Attached is my code...

    Thanks,
    Ron

    DummyLoad2.bas

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


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Hi Ron, and welcome to the forum. Do you have a schematic you can share? I'm wondering if the problem is hardware and not software.

  3. #3
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    scalerobotics:

    Thanks for the reply. The schematic is very simple. It is a 10 turn 50k POT, one side tied to 5.013 Vdd, the other side tied to Vss. The center tap of the POT is connected to AN0 of the PIC16F873A. I currently have a 2.2uf cap tied to Vss at AN0.

    The readings on the display are stable, I'm able to adjust the POT fully clockwise and counterclockwise and get a reading of 0 to 1023 on the display.

    The problem is between 0.000 and 0.063 Vdc in on AN0 the ADC count is 0, and at 2.500 Vdc the ADC count is 505. At 5.00 Vdc the ADC count is correct, it reads 1023.

    The 16F873A datasheet, table 17-14, A/D converter characteristics, parameter A25 states the analog voltage input is Vss-0.3V to Vref+0.3V.

    I have set via the ADCON the VREF- to = Vss, and VREF+ to = VDD, and I have set the ADC to 10 bit. I would expect ADCin to give a ADCcount of 0 at 0.000V and a count of 1 at 0.048V, 512 at 2.500V, and 1023 at 5.00V.

    Thanks,
    Ron

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Try a lower value POT - 2.5k or so (see circled data below).
    Attached Images Attached Images  
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  5. #5
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    rmteo:

    I changed the pot to ten turn 2k ohm, also tried a ten turn 20k ohm. No change, it reads exactly the same as before. The ADC is not reading correct, between 0.000 and 0.063 Vdc in on AN0 the ADC count is 0, and at 2.500 Vdc the ADC count is 505. At 5.000 Vdc the ADC count is correct, it reads 1023. It is strange that the closer I get to Vdd the more correct the ADC gets. This thing should read 1 count for every 4.8 mV, and its not. I have tried using other chips, such as its big brother the 16F876, and its cousin the 16F819.

    At first I suspected my Keithley 175, however I have tried other meters and a scope and they all read the exact same as my Keithley.

    Thought about ripple, there is about 1mV. If it were reading the ripple I would at least get a count from the ADC. What is bothering me is that I do not get a count from the ADC until I get over 0.063 Vdc at AN0.

    Anyone else have any ideas?

    Thanks,
    Ron

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Hey RDavid,

    At this point, if I were you, I would drop back to some trouble shooting techniques.

    How about using debug to send the adval to a serial port or if you are using the PICkit programmer it has that feature available.

    Below is a sample program for the 16F690 so you will have to adapt it for your PIC, but you can see how to set up debug.


    Code:
    ' 16F690
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 12/4/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ' 10-bit A/D conversion 
    ' Connect analog input to channel-2 (RA2)
    ' -----[ I/O Definitions ]-------------------------------------------------
     DEFINE DEBUG_REGG PORTA        'set debug port to porta
     DEFINE DEBUG_BIT 0             'use pin a0 of porta for debug
     DEFINE DEBUG_BAUD 2400         'set baud rate to 2400
     DEFINE DEBUG_MODE 0            'communicate in true mode
     
    ' Define ADCIN parameters
    ' Set number of bits in result
    DEFINE  ADC_BITS        10 
    ' Set clock source (3=rc)
    DEFINE  ADC_CLOCK       3   
    ' Set sampling time in microseconds
    DEFINE  ADC_SAMPLEUS    50     
    adcVar  VAR WORD ' Create variable to store result
    ' Set PORTA to all input
    'TRISA = %11111111     
    ' Set up AD
    ANSEL  = %00000100  'enable AN2, ALL THE REST DIGITAL
    ANSELH = %00000000  'AN8-11 DIGITAL
    ADCON0 = %10001000   ' RIGHT JUSTIFIED
    ADCON1 = %00010000  'fOSC/8     
    Pause 500               ' Wait .5 second
    main:  
      ADCIN 2, adcVar ' Read channel 0
      ' do something with adVar here
      debug DEC adcvar,"  ",BIN adcVar,$0D,$0A
      Pause 100              ' Wait.01 second
    GoTo main                   ' Do it forever
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  7. #7
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Dwight:

    Thanks, I was already using Debug to send the ADCin value to one of my PicKit2 using the UART tool. It's pretty cool, if you have two PicKits you can use two at a time, one as a programmer running under MicroCode studio and the another as a debugger spitting out data from your code.

    Any way thanks to everone for their help. I got it to correctly read the ADC.

    The issue was that if I leave any pin on PortB high it would throw off my ADC readings on the low end. I found that if I make all the bits on PortB low before reading the ADC the reading are accurate. Go figure!

    Thanks again for all the help.

    Ron

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    That is strange. I checked section 11 of PIC 16F87x and there is no reference to Port B. It does mention Port E, but the 16F873 doesn't have that port.

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


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    How about the config fuses? Smells of PGM in LVP mode to me, OR there<s some psu noise, or floating MCLR pins.. go figure

    As usual, 10uF tantalum + 0.1uF as close as possible of VDD, make sure you have both VSS pins connected, 10K or so on MCLR.
    Last edited by mister_e; - 16th May 2011 at 08:30.
    Steve

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

  10. #10
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Steve:

    Here are the conifgs:
    @ device pic16F873A, HS_OSC ' High Speed Crystal/Resonator, 4 MHz and above
    @ device pic16F873A, WDT_ON ' Watchdog timer enabled
    @ device pic16F873A, PWRT_ON ' Power on timer enabled
    @ device pic16F873A, BOD_ON ' Brown out detect enabled

    There is a 0.1uf between Vss and Vdd

    The Vdd has less than 1mV of ripple.

    Both Vss pins are tied to ground.

    I added the following to my configs, still no change.
    @ device pic16F873A, LVP_OFF ' Low-Volt ICSP programming disabled

    With any of PortB pins high the ADC will not respond until AN0 is above 0.063Vdc. If I ensure that all PortB pins are low the ADC responds correctlty.

    I even added a 100 mS pause before and after issuing the ADCIN statement, that helped some, but didn't solve the issue.

    In this aplication it's not a problem. I ensure that all pins on PortB are low before reading the ADC. The ADC now correctly reads 1 count for every 0.0488 volts.

    Thanks,
    Ron

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    I often use a 16F877, sister chip to your 16F873, and never had this problem.

    The manual says to pull-down the PGM pin.

    It also goes on to say that it is best to disable LVP during regular programming (low voltage programming can be used during in-circuit-programming).

    What about MCLR, is that pulled up to VDD?

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


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Try something, load the PGM pin to gnd with a pull down resistor (says 1K), if it works, then the chances are that your device programmer don't program the fuses properly.

    On the other hand, a nasty breadboard could do some problem. Some have broken power strip along the way. It still looks like a bad Vss connection to me.

    EDIT: Program your device, but before check the fuses settings in your device programmer software to see if they match your program. If so, program your device... then read it back. Se if the fuse setting remain the same. Case not, throw your device programmer away Nah, sometimes, just a pull down resistor on the PGM pin while programming is needed. Try it!
    Last edited by mister_e; - 17th May 2011 at 20:08.
    Steve

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

  13. #13
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Help with ADCin

    Demon and Steve:

    Thanks for the sugestions guys, tried them to no avail.

    I don't have a 16F877, but I do have a 16F876. Tried it and it does not make a difference. Also tried a 16F819 it also behaves the same way.

    Tried 1k pull down on PGM pin, no difference.

    LVP is disabled in programmer. BTW, it's a PicKit 2, I have two of them both program fine. I can change the fuse settings and verify that the changes are making it to the PIC.

    Now as to the breadboard. The breadboard that I normaly use is chocked full of another project (thats another story), so I borrowed one form my son, its a cheap-O from Jameco. Now that you bring it up, I'm starting to question if it might be the problem... I'm going to build this circuit up on a custom PCB and see it that solves the problem. Might very well be the culprit.

    Very strange that I have to ensure that all pins on PortB are low before the ADC will read below 0.063 Vdc on AN0.

    Thanks,
    Ron

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