SOLVED: How can I reduce ADC jitter


+ Reply to Thread
Results 1 to 40 of 96

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    Code:
    ADCshift = NewADC0 >> 2
    I shifted the results 2 bits, expecting to lose any jitter from 0 - 3, but I still get jitter.

    I bet it's when a number jumps an upper bit, like 00100011 to 01000100.

    I'm using 10-bit ADC, so chopping 2 bits already bring me down to 256 increments.

    Bringing it down more won't solve when it's a higher jump, like 00111111 to 01000000


    EDIT: Divide by 4 doesn't help either, I still get jitter, even on the voltage-divider.
    Last edited by Demon; - 24th February 2025 at 08:26.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,694


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    changing my test to rs 2 digits

    jitter negligible
    Code:
    mean 159
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3596  0004,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 159
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 159
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3598  0002,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 159

    Code:
    #CONFIG    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_ON
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    
        DEFINE OSC 32
        
        DEFINE DEBUG_REG PORTD
        DEFINE DEBUG_BIT 2      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0 
        
        DEFINE ADC_BITS 10                 ' 10-bit Analog to digital
        DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
        
        ANSELA = % 00000001                      ' Pin A0 = ADC
        TRISA = % 11101111                       ' Pin A4 = LED
        TRISD = % 11111011                       ' DEBUG 
        LATD.2 = 1                              ' DEBUG 
        clear
        LED VAR LATA.4
        i var byte
        j var word
        bucket              var WORD
        ADCinput            var WORD
        mean                var WORD
        buckets             var word[21] 
        outlier             var WORD                       
        LED = 1                                  'Proof of Life 
        PAUSE 2000  
        DEBUG 13,10,"READY",13,10 
        FVRCON = % 10000011
        ADCON0 = % 10010100
        ADREF  = % 00000000
        ADPRE  = 48
        ADCLK  = 32
        ADCAP  = 31
        LED=0
    
    
    Mainloop:
        mean = 0
        for i = 0 to 9
        ADCIN 0, ADCinput
        mean = mean + ADCinput
        next
        mean = mean/40 ;average divide 4
        DEBUG "mean ",DEC mean,13,10
        for j = 0 to 3599
        ADCIN 0, ADCinput
        ADCinput=ADCinput>>2
        bucket = mean-ADCinput
        i = bucket + 10
        
        if i>20 then  
          outlier =  outlier + 1
        else
          buckets[i]=buckets[i] + 1
        endif
        'DEBUG 13,10,"mean ",DEC mean," i ",dec i," read ",dec ADCinput,13,10
        
        PAUSE 5
        next
        DEBUG "readings " ,13,10
        DEBUG  dec4 buckets[0],",", dec4 buckets[1],","  , dec4 buckets[2],",", dec4 buckets[3],"," , dec4 buckets[4],","
        DEBUG  dec4 buckets[5],",", dec4 buckets[6],","  , dec4 buckets[7],",", dec4 buckets[8],"," , dec4 buckets[9],"  "
        DEBUG  dec4 buckets[10],"  "
        DEBUG  dec4 buckets[11],",", dec4 buckets[12],","  , dec4 buckets[13],",", dec4 buckets[14],"," , dec4 buckets[15],","
        DEBUG  dec4 buckets[16],",", dec4 buckets[17],","  , dec4 buckets[18],",", dec4 buckets[19],"," , dec4 buckets[20],13,10
        DEBUG  "outliers ",dec4 outlier 
        DEBUG  13,10
        for i = 0 to 20
          buckets[i] = 0
        next
        outlier = 0
          
        GOTO Mainloop
    end
    Warning I'm not a teacher

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,694


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    using the fvr gets slightly better result [mine is a 3.3v system]

    Code:
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255




    Code:
    #CONFIG    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_ON
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    
        DEFINE OSC 32
        
        DEFINE DEBUG_REG PORTD
        DEFINE DEBUG_BIT 2      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0 
        
        DEFINE ADC_BITS 10                 ' 10-bit Analog to digital
        DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
        
        ANSELA = % 00000001                      ' Pin A0 = ADC
        TRISA = % 11101111                       ' Pin A4 = LED
        TRISD = % 11111011                       ' DEBUG 
        LATD.2 = 1                              ' DEBUG 
        clear
        LED VAR LATA.4
        i var byte
        j var word
        bucket              var WORD
        ADCinput            var WORD
        mean                var WORD
        buckets             var word[21] 
        outlier             var WORD                       
        LED = 1                                  'Proof of Life 
        PAUSE 2000  
        DEBUG 13,10,"READY",13,10 
        FVRCON = % 10000010;2.048v
        ADCON0 = % 10000100
        ADREF  = % 00000011,fvr
        ADCLK  = 16; faster clk
        LED=0
    
    
    Mainloop:
        mean = 0
        for i = 0 to 9
        ADCIN 0, ADCinput
        mean = mean + ADCinput
        next
        mean = mean/40 
        DEBUG "mean ",DEC mean,13,10
        for j = 0 to 3599
        ADCIN 0, ADCinput
        ADCinput=ADCinput>>2
        bucket = mean-ADCinput
        i = bucket + 10
        
        if i>20 then  
          outlier =  outlier + 1
        else
          buckets[i]=buckets[i] + 1
        endif
        'DEBUG 13,10,"mean ",DEC mean," i ",dec i," read ",dec ADCinput,13,10
        
        PAUSE 5
        next
        DEBUG "readings " ,13,10
        DEBUG  dec4 buckets[0],",", dec4 buckets[1],","  , dec4 buckets[2],",", dec4 buckets[3],"," , dec4 buckets[4],","
        DEBUG  dec4 buckets[5],",", dec4 buckets[6],","  , dec4 buckets[7],",", dec4 buckets[8],"," , dec4 buckets[9],"  "
        DEBUG  dec4 buckets[10],"  "
        DEBUG  dec4 buckets[11],",", dec4 buckets[12],","  , dec4 buckets[13],",", dec4 buckets[14],"," , dec4 buckets[15],","
        DEBUG  dec4 buckets[16],",", dec4 buckets[17],","  , dec4 buckets[18],",", dec4 buckets[19],"," , dec4 buckets[20],13,10
        DEBUG  "outliers ",dec4 outlier 
        DEBUG  13,10
        for i = 0 to 20
          buckets[i] = 0
        next
        outlier = 0
          
        GOTO Mainloop
    end
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    Quote Originally Posted by richard View Post
    using the fvr gets slightly better result [mine is a 3.3v system]

    Code:
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255
    readings 
    0000,0000,0000,0000,0000,0000,0000,0000,0000,0000  3600  0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
    outliers 0000
    mean 255

    My readings never jitter at 0000 or 1023, always rock solid.

    It's when I start taking readings within the range that things go nuts.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,694


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    We can't switch ADPCH manually between each Average?
    not really
    it needs to take the number of readings to average in an uninterrupted exclusive sequence
    once the average is obtained you can set a new channel and set the device to perform a new average
    or cease averaging. a sequence cannot be interrupted for an additional extra adc read


    I'm trying to switch ADPCH to 111100 = AVSS (Analog Ground) before each ADCIN to see if that fixes the problem.
    or makes it worse if acquisition time is inadequate or marginal , the dummy read is most successful
    not sure about this chip but when does channel change occur, a delay is probably required

    i don't see any form of averaging here

    Code:
    ADPCH = AVSS : adcin 0, ADCinput
    NewADC0 = 1023 - ADCinput ' inverted so pot goes from 0 to 1024
    
    
    if NewADC0 <> oldadc0 then
    oldadc0 = NewADC0
    ADCshift = NewADC0 / 4
    LCDOUT $FE, $94+6, DEC4 oldadc0, " ", dec4 ADCshift : Pauseus 1
    endif
    Warning I'm not a teacher

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,694


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    there are heaps of other ways too

    mean var word
    ADCinput var word


    average

    Code:
        mean = 0
        for i = 0 to 9
        ADCIN 0, ADCinput
        mean = mean + ADCinput
        next
        mean = mean/10 
        DEBUG "mean ",DEC mean,",",DEC mean>>2,13,10

    running average
    Code:
       ADCIN 0, ADCinput
       mean = mean */ 200 + ADCinput */ 55
       DEBUG "mean ",DEC mean,",",DEC mean>>2,13,10
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    Quote Originally Posted by richard View Post
    ...i don't see any form of averaging here...
    There isn't. I thought it all happened in the background when you did ADCIN, the average was calculated, and results stored in output fields, like a normal ADCIN.


    I guess you're telling me this is an on-going process, and ADCIN just gives you the average "at that point in time", but it keeps on going.


    I thought setting this OFF meant we could disable continuous sampling:

    16F18855

    23.5.8 CONTINUOUS SAMPLING MODE

    Setting the ADCONT bit in the ADCON0 register automatically retriggers a new conversion cycle after updating the ADACC register.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,694


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: SOLVED: How can I reduce ADC drift

    I guess you're telling me this is an on-going process, and ADCIN just gives you the average "at that point in time", but it keeps on going.
    the computational adc is more complex than that, microchip have a number of YT clips on it usages

    eg



    i have never had any reason to use it to date
    Warning I'm not a teacher

Similar Threads

  1. SOLVED - IOC works on B0 but not B5
    By Demon in forum General
    Replies: 19
    Last Post: - 26th September 2024, 22:11
  2. Replies: 6
    Last Post: - 5th November 2023, 17:26
  3. trying to reduce current consumption on a 12HV615
    By Max Power in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th November 2011, 15:57
  4. Unwanted output signal jitter
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th January 2008, 03:31
  5. Dmx Solved !!!!!!!
    By oscar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 2nd July 2005, 22:57

Members who have read this thread : 15

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