18LF14K22 AD Converter Problem


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    48

    Default 18LF14K22 AD Converter Problem

    Hi all,
    i have the following problem:
    I use Aanalog 2 (RA2) and Analog 3 (RA4) to measure DC Voltage on a PIC18LF14K22.

    The uP is configured to run with internal oscillator:
    OSCCON = %01110010 ' configure internal OSC @ 16MHZ
    OSCTUNE = %00000000
    While OSCCON.2=0 : wend ' wait until OSC is stable

    After that i configure Port A to use RA0 to RA3 as ADC:

    TRISA = %111111
    ADCON1 = %00000000
    ADCON2 = %10000111 ' Right justified, Frc
    ANSEL = %00001111
    ANSELH = %00000000

    Then in two subroutines i read back Aanalog 2 and Analog 3:

    1:
    ADCON0 = %00001011 ' Start the conversion of ad channel 2
    WHILE ADCON0.1 = 1 ' Wait for it to complete
    i = 0
    WEND
    adc2_value = (adc2_value + ((ADRESH * 256) + ADRESL)) / 2 ' get result from AN2 with avg by two

    2.
    ADCON0 = %00001111 ' Start the conversion of ad channel 3
    WHILE ADCON0.1 = 1 ' Wait for it to complete
    i = 0
    WEND
    adc3_value = (adc3_value + ((ADRESH * 256) + ADRESL)) / 2 ' get result from AN3 with avg by two

    The result vars are defined as word.

    Now the problem:
    1. Always delivers correct values

    2. Brings always the same value (50), but it should vary between 50 and 200...

    Don't know the reason why Analog 3 is always same value, can somebody help!?
    Regards,
    Ralf

  2. #2
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Read the Errata Datasheet :-(

    http://ww1.microchip.com/downloads/e...Doc/80437B.pdf

    1. Module: ADC (Analog-to-Digital
    Converter)
    ADC conversion on AN3/OSC2 will have large INL
    error up to approximately 8 LSb.
    Work around
    None for the AN3 pin. For better accuracy, use
    another analog pin.

    This PIC is a Big Bug Chip !

    Regards,
    Ralf

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    Hi, Ralph

    May be you also could leave some sampling time to both channels ... ( you've set it to ZERO Tad) ...

    Results would be ... less false !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Hi,
    thanks for the answer.
    But: No effect. AN3 on this chip seems to be absolutely not useable.

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