ADC values above 4095 for 12 bit ADC


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default ADC values above 4095 for 12 bit ADC

    seeing some readings when doing ADC on a channel giving a dec value 5534, 5144, ect when using ADCIN

    have defines set to 12 bit

    the adc channel is grounded via 26k resistor for testing


    problem is i cant see why the reading is there at such a high value , and the value should not exceed 4095

    any thoughts on why this may be happening ?????????




    cheers


    sheldon

    Code:
       DEFINE OSC 32              ' Timing referance for pause , pauseus commands
        DEFINE ADC_BITS 12         ' Number of bits in ADCIN result - Required for adcin command 
    
    
    
     ADCON1 =  %00100000           ' bit 7-6 = TRIGSEL 11= triger from RTCC, 10 = trigger from timer1 ,01 = trigger from CTMU, 00= trigger from ECCP2
                                    ' Bit 5-4 - VCFG+ 11= Internal VREF+(4.096v) ,10= Internal VREF+ (2.048v) 01=External VREF+ ,00= AVDD
                                    ' Bit3 - VNCFG-  1= External Vref- ,  0= AVSS Vref/A ,
                                    ' Bit 2-0 = Analoge Neg Ch Select ( Differential measurement ) 
                                    ' 111 = AN6, 110 = AN5, 101 = AN4,100 = AN3,011 = AN2, 010 = AN1, 001 = AN0,000 = AVSS,
      
      ADCON2 =  %10010010           ' bit 7 = 1 ADFM ( ADRESH, ADRESL - right justify ) , Bit6 n/a , 
                                    ' Bits 5-3 ACQT ( acquision time ) 111 = 20TAD ,110=16TAD,101-12TAD,100=8TAD,011=6TAD,010=4TAD,001=2TAD,000=0TAD
                                    ' Bit 2-0 ADCS ( AD clock sel) x11 =FRC , 110=Fosc/64,101= FOSC/16 ,100=FOSC/4 ,010=FOSC/32 ,001=FOSC/8, 000=FOSC/2
                                    ' Note:  define ADCIN clock  and define ADcin sample overide this setting   
    
    
    
    
    
     ANCON2.1 = 1              ' Set PortG.3 = 1 - Select portG.3 to Analog  - AN17 - AD touch switch input 1R-TX mode
         TRISG.3  = 1              ' Set TRISG.3 = 1 - Select portG.3 to Input   - AN17 - AD touch switch input 1R-TX mode
         ADCON0 = %01000111        ' Select the A/D channel - AN17 turn on a/d 
    
    
      adcin 17,value1            ' do ADC reading on AN17 - touch switch input 
         HSEROUT2 ["value1 = ",dec4 value1,13,10]
    
      ADCON0 = %01000100        ' Select the A/D channel - AN17 and turn off A/D module


    Code:
    value1 = 0003
    value1 = 0004
    value1 = 0002
    value1 = 0011
    value1 = 0005
    value1 = 0003
    value1 = 0004
    value1 = 0004
    value1 = 0005
    value1 = 0006
    value1 = 0004
    value1 = 0003
    value1 = 0005
    value1 = 0004
    value1 = 0004
    value1 = 0004
    value1 = 0003
    value1 = 0005
    value1 = 0002
    value1 = 0002
    value1 = 0005
    value1 = 0005
    value1 = 5535
    value1 = 5525
    value1 = 0004
    value1 = 0008
    value1 = 0002
    value1 = 0001
    value1 = 0004
    value1 = 0002
    value1 = 5534
    value1 = 5532
    value1 = 0005
    value1 = 0077
    value1 = 5529
    value1 = 0004
    value1 = 0008
    value1 = 0020
    value1 = 5524
    value1 = 5229
    value1 = 0025
    value1 = 0057
    value1 = 0002
    value1 = 5283

  2. #2
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    I think it may be a hardware problem with that ad channel , as testing other channels i dont have the problem

  3. #3
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    You didn't tell what PIC you use. It can make big difference...
    For example PIC18F87K22 have differential inputs, and negative results are two’s complement of result. So for -1 = $FFFF, -2 = $FFFE etc.
    You can use SDEC to get correct result.
    Or you can use this:
    Code:
    ADCIN 17,value1 'I'm not sure how ADCIN in handles negative numbers... So maybe manual reading of ADRES registers are better solution
    IF value1.1 = 1 THEN           
        Sign="-"
    ELSE
        Sign=" "
    ENDIF
    value1=ABS(value1)
    HSEROUT2 ["value1 = ",Sign, dec4 value1,13,10]
    Last edited by pedja089; - 31st January 2015 at 11:20.

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    thats a good thought about a negative input , and clearly the value for negative flag is being set

    the 18f67k22 , which i am using, Has AN0-AN6 as negative inputs , for differential input , selected by ADCON1- BITS 2-0 , where 00 = AVSS. and they are not being set

    AN4 is used for is used for ad input every 20 secs , but at no time is it set to a negative ref , by adcon1

    AD17 is part of comparitor 3 input , which is set to 0 so that should not be affecting it

    its got be stumped what setting maybe forcing the neg value ,

    and it feel like i have a setting wrong some where for an17

    i have moved to an7 to continue sorting out the CTMU for touch switch service , which has helped get a more consistent reading to sort out the touch function

    the CTMU is nice bit of the PIC chip "IF" you can work your way around all the possible settings including the interrupts ,

    i also note that the DT'S INts_18_k22.bas does not support the CTMU intrerupt for external pin triggering , and will need to be added or do it via a manual clearing of interupts , but thats for later

  5. #5
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    Offset can be from internal differential amp or multiplexers. Inverting input is tied to GND when used in single input mode. You connect non inverting input also to GND. So any input offset or positive offset in inverting input multiplexer can produce small negative result, which look as large positive number.

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    yep i cant see where it coming from , but it was not hard to use another a/d channel , but its something that i need to look at closer

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


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    010=4TAD
    may be too short a time to get full conversion ???

    and especially @ 32 Mhz !!! ( have a look to datasheet ... )

    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 " !!!
    *****************************************

  8. #8
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: ADC values above 4095 for 12 bit ADC

    looking at table 23.1 4 tad should be ok at 32 mhz, using the setting of Fosc/32 for ADCS ???


    Name:  tad table.JPG
Views: 711
Size:  92.7 KB
    Name:  tad conversion.JPG
Views: 624
Size:  92.9 KB
    Name:  ad conversion spec.JPG
Views: 609
Size:  169.4 KB

Similar Threads

  1. Scaling ADC values
    By purkolator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th November 2007, 06:14
  2. Flash PIC with 12 bit ADC
    By Steve_88 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th October 2007, 21:35
  3. Adc giving widely flactuating values
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th December 2006, 09:59
  4. MAX1247 4-Channel, 12-Bit ADC
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 16th December 2006, 00:38
  5. Need help with 16f819 10 bit ADC
    By bannrikae in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th September 2005, 16:20

Members who have read this thread : 2

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