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

    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.

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