ADC Help Please


Closed Thread
Results 1 to 15 of 15

Thread: ADC Help Please

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Works great now. Thanks.

    BrianB

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    Hi everyone,
    I am following up on that ADC config issue, as I have troubles to make my project (based on a 16F884) to work.

    Here is the hardware part:

    The project is a nixie clock with other fancy stuffs (thermometer, hygrometer...). That is, I use the analog module to read various sensors. Additionally, due to the lack of I/O, I use an "analog" keypad consisting of 3 pushbuttons that each produce a different voltage (with resistor combinations).

    So far, I can only get erratic values out of the ADC no matter which A/D pin I'm reading... It is varying as if the pin was connected to an antenna and reading noise (with completely random variations from min to max!). I also tried to ground one of the analog I/O to read it, and the results are actually pulled towards 0, but can still get as high as 300.

    I don't thing the hardware is wrong on that one, I have a steady 5V powersupply, checked with a scope, also sensor output were checked and don't fluctuate more than a few mV. I also included capacitors between inputs and ground... and everything is mounted on a nice dual side PCB.

    The only source of noise would be my buck-boost switch, that I use to get the 180V for the tubes, but I don't see much noise when I look on the analog lines with my scope.

    This is why i'm suspecting a software or config problem, but can't work it out. And since there's issue with this family I'd like to make sure i'm not doing anything wrong.
    Here is parts of my program, I added the workaround posted above in the config:

    DEFINE OSC 20
    DEFINE LOADER_USED 1

    'set up the ADC with special workaround for the 16F88x family
    DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
    DEFINE ADC_CLOCK 0 ' Work around that sets Vref bits in ADCON1
    DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)
    ADCON0=ADCON0 | %11000000 ' Work around that sets ADCS in ADCON0

    'Set oscillator configuration to run on external oscillator
    OSCCON = %00000000

    'Set comparators off
    CM1CON0 = %00000000
    CM2CON0 = %00000000

    'Set analog input AN0, AN1, AN2, AN3, AN4 and AN5
    ANSEL = %00011111
    ANSELH = %00000000
    ADCON1 = %00000000
    'ADCON0 = %01000001

    'Set PortA as input or output
    PORTA = %00000000
    TRISA = %00101111
    'Set entire PortB as digital input
    PORTB = %00000000
    TRISB = %00000000
    'Set entire PortC as digital input
    PORTC = %00000000
    TRISC = %00000000
    'Set entire PortD as digital input
    PORTD = %00000000
    TRISD = %00000000
    'Set PortE0 as input or output
    PORTE = %00000000
    TRISE = %00000001

    ---------------------------

    '************************************************* ******
    'Read the keypad
    '************************************************* ******
    ReadPushButtons:
    'Mode/UP 0.47V
    'Date/DOWN 2.6V
    'SET 5.0V

    ADCIN 5, ButtonValue

    Return

    ---------------------------

    All other (non analog) functions are working great otherwise...!
    Any help apreciated

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    1 = Input
    0 = Output
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    Hmm good catch! I forgot AN5 which was purposedly the one I'm trying to read...!

    Here is ANSEL now:
    'Set analog input AN0, AN1, AN2, AN3, AN4 and AN5
    ANSEL = %00111111

    However that hasn't changed anything, for AN5 or the other sensors (AN4 to AN0).

    Going through the 16F884 datasheet again to check these registers.

    I remember doing this lately on a 16F877A whithout much troubles!

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


    Did you find this post helpful? Yes | No

    Default

    Compiler version?
    Steve

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

  6. #6
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    It is PBP 2.50

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Take the advise from Bruce in post 5.
    Here is an example for a different chip, but you will get the idea. Works much nicer.
    http://rentron.com/PICX2.htm

    And it may not be causing you trouble now but it could ...Maybe you got my hint...
    'Set entire PortB as digital input
    PORTB = %00000000
    TRISB = %00000000
    'Set entire PortC as digital input
    PORTC = %00000000
    TRISC = %00000000
    'Set entire PortD as digital input
    PORTD = %00000000
    TRISD = %00000000
    1 = Input
    0 = Output
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 03:18
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 19:29
  3. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 16:33
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 16:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 02:55

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