Help with ADCin


Closed Thread
Results 1 to 13 of 13

Thread: Help with ADCin

Hybrid View

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

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

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

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

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

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    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.

  7. #7
    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 09:30.
    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