SOLVED: How can I reduce ADC drift


+ Reply to Thread
Results 1 to 22 of 22
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969

    Post SOLVED: How can I reduce ADC drift

    SOLVED: Noisy VDD/VSS using DC-DC converter. ADC stopped bouncing after using a 7805.

    https://picbasic.co.uk/forum/showthr...527#post156527

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


    16F18877

    - Using fixed input on ADC pin (1K to VDD, 1K to VSS - simulating pot at 50%)
    - The ADC will drift from 498 to 509.

    HSEROUTs on Serial Communicator:
    Low=00498 High=00509

    Is there anything in the registers that I can "tune" for the ADC?

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _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_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    
    DEFINE  ADC_BITS 10                 ' 10-bit Analog to digital
    
    define  CCP1_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP1_BIT     0
    define  CCP2_REG     0
    DEFINE  CCP2_BIT     0
    DEFINE  CCP3_REG     0
    DEFINE  CCP3_BIT     0
    define  CCP4_REG     0
    DEFINE  CCP4_BIT     0
    define  CCP5_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP5_BIT     0
    
    DEFINE  HSER_RXREG PORTC
    DEFINE  HSER_RXBIT 7
    DEFINE  HSER_TXREG PORTC
    DEFINE  HSER_TXBIT 6
    
    DEFINE  HSER_RCSTA 90h              ' Enable serial port & continuous receive
    DEFINE  HSER_TXSTA 24h              ' Enable transmit, BRGH = 1
    Define  HSER_BAUD 115200
    DEFINE  HSER_CLROERR 1              ' Clear overflow automatically
    DEFINE  HSER_SPBRGH  0
    DEFINE  HSER_SPBRG  68
    
    BAUDCON.3 = 1                       ' Enable 16 bit baudrate generator
    
    RA4PPS = 0                          ' Disable CCP5
    RB0PPS = 0                          ' Disable CCP4
    RB5PPS = 0                          ' Disable CCP3
    RC1PPS = 0                          ' Disable CCP2
    RC2PPS = 0                          ' Disable CCP1
    
    IOCAP = %00000000                               'IOC Positive Edge, low-to-high
    IOCAN = %00000000                               'IOC Negative Edge, from high-to-low
    IOCBP = %00000000                               'IOC Positive Edge, low-to-high
    IOCBN = %00000000                               'IOC Negative Edge, from high-to-low
    IOCCP = %00000000                               'IOC Positive Edge, low-to-high
    IOCCN = %00000000                               'IOC Negative Edge, from high-to-low
    'IOCDP = %00000000                              '...not available
    'IOCDN = %00000000                              '...not available
    'IOCEP = %00000000                              '...not available
    'IOCEN = %00000000                              '...not available
    
    WPUA = %00000000                        ' Pull-up resistors
    WPUB = %00000000
    WPUC = %00000000
    WPUD = %00000000
    WPUE = %00000000
    
    INLVLA = %00000000                      ' TTL input level
    INLVLB = %00000000
    INLVLC = %00000000
    INLVLD = %00000000
    'INLVLE = %00000000                      ' ...only available on E3 / MCLR pin
    
    ADCON0 = %10000100                      ' ADC CONTROL REGISTER 0
    ADCLK  = %00111111                      ' ADC CLOCK SELECTION REGISTER
    'ADPCH  = %00011010                      ' Channel 26 - D2
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000110                      ' Pin D2 = ADC input, NavCom
                                            ' Pin D1 = ADC input, Glareshield
    ANSELE = %00000000
    
    TRISA = %00000000                       
    TRISB = %00000000                       
    TRISC = %00000000                       
    TRISD = %00000110                       
    TRISE = %00000000
    
    include "I:\Project_v2\PBP\PBP_Includes\USART.bas"
    
    ADCInput                var word
    
    LowADC                  var word
    HighADC                 var word
    
        Pause 1                                     ' Let PIC stabilize
    
        LowADC = 1023
        HighADC = 0
        AdcInput = 0
    
    Mainloop:
    
        adcin 26, AdcInput
        
        if AdcInput < LowADC then LowADc = AdcInput
        if AdcInput > HighADC then HighADC = AdcInput
            
        hserout [   "Low=", dec5 LowADC, "  High=", DEC5 HighADC, 10  ]                             
     
        goto mainloop
    end
    I was getting desperate with the drift on the pots, so I thought I'd do a control run using resistors.

    I expected it to remain the same or very close, but I'm still getting drift.
    Last edited by Demon; Yesterday at 03:37.
    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,514


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    50mV of noise on the power supply would do that.
    using FVR as adc ref might help a little and or a better regulator for the pots
    Warning I'm not a teacher

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    I use a DC-DC converter to lower 12V down to 5V for the entire circuit.

    Would a dedicated 7805 for the pots be a "meaningful" improvement?

    I'll have up to 10 pots in the final circuit. Right now I'm trying to get 1 ADC working well.
    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!

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Would a dedicated 7805 for the pots be a "meaningful" improvement?
    the first step is to measure the noise on the power rail and then to determine if that's an issue, there is no point adding a regulator for the pots if the adc pos reference is noisy
    Warning I'm not a teacher

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Based on the fact that you are using Power Supply as a reference voltage for the ADC:

    1. the Power Supply noise is random and in the length of time it would have very minimal effect on the adc average value.

    2. you are feeding the ADC input from a resistor divider that is connected to the Vdd, where also the reference voltage is connected to. It is called ratiometric and should zero the effect of regulator voltage drift. If the voltage of the Resistor divider changes by x % then the reference voltage will change by x % too. So eventually no drift should happen.

    What you experience is strange and should not happen.

    Needs more investigation.

    If you heat or cool the PIC chip, is there any change?

    Ioannis

    P.S. If you finally use external Voltage reference, that is reasonably stable, I feel that the results will be even worse, because then the Vdd change will have maximum effect on the voltage sample.
    Last edited by Ioannis; - 31st October 2024 at 10:55.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    The Vdd that resistors are connected to, is the exact same point that PIC Vdd pin is connected also?

    Ioannis

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Quote Originally Posted by Ioannis View Post
    The Vdd that resistors are connected to, is the exact same point that PIC Vdd pin is connected also?

    Ioannis

    Yes, it is.
    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
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Temperature (heating or cooling PIC) has any effect on the drift?

    Ioannis

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Quote Originally Posted by Ioannis View Post
    Temperature (heating or cooling PIC) has any effect on the drift?

    Ioannis
    I'm curious how can this help me?

    It is room temperature, just like target customer environment (gaming).

    It's not like I'm overclocking the PIC like a PC CPU...?
    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!

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    If the ADC result has no or minimal effect because of temp then we have to look elsewhere for the drift.

    Ioannis

  11. #11
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    170


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    I would try the following:

    1/. Use the Fixed Voltage Reference (FVR) instead of Vdd as your ADC reference voltage.
    2/. Add some capacitance - say 100nF - between the pot wiper and ground.

    Cheers
    Barry
    VK2XBP

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Quote Originally Posted by Aussie Barry View Post
    I would try the following:

    1/. Use the Fixed Voltage Reference (FVR) instead of Vdd as your ADC reference voltage.
    2/. Add some capacitance - say 100nF - between the pot wiper and ground.

    Cheers
    Barry
    VK2XBP
    1. Yeah, FVR is on my TO-DO list (Richard mentioned it up there).

    2. Does it matter if the cap is at the switch or up against PIC (like decoupler caps).

    3. Temp is also on my TO-DO list.
    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!

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    also try using the fastest conversion clock that does not go Outside the recommended TAD time.
    you are using the slowest possible clock
    if you use the fvr don't let the wiper volts exceed the fvr output volts
    Warning I'm not a teacher

  14. #14
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    170


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    It shouldn't really matter if the cap is at the PIC end or the Pot end, as long as the distance between both is not too great.
    Note the silicon errata document (Item 1.3) regarding the use of FVR as ADC reference voltage:
    https://ww1.microchip.com/downloads/...-80000702J.pdf

    Cheers
    Barry

  15. #15
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    170


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Quote Originally Posted by richard View Post
    if you use the fvr don't let the wiper volts exceed the fvr output volts
    What happens if the wiper voltage exceeds the FVR voltage?

  16. #16
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    170


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Quote Originally Posted by Demon View Post
    16F18877


    Is there anything in the registers that I can "tune" for the ADC?
    The PIC16F18877 has an Analog-to-Digital converter with Computation
    These post-processing functions are applied to the ADC conversion result and include averaging and low-pass filtering.

    Cheers
    Barry

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    What happens if the wiper voltage exceeds the FVR voltage?
    Ain specs from datasheet

    Name:  Screenshot 2024-11-02 121344.jpg
Views: 25
Size:  137.8 KB


    at best the top range of the pot would be useless
    Warning I'm not a teacher

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Using FVR will make things worse...

    Ioannis

  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    I thought I'd step back and check VDD and VSS using my SDS1104 scope.

    This is at 50mV:

    Name:  SDS1104 scope VDD.jpg
Views: 17
Size:  140.7 KBName:  SDS1104 scope VSS .jpg
Views: 17
Size:  136.6 KB


    Is it realistic to expect no drift on ADC with this much noise on my lines?
    Last edited by Demon; - 2nd November 2024 at 20:15.
    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!

  20. #20
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    CONFIRMED: Noisy power definitely messes up everything when the PIC tries to compare the "wiper" reading with VDD/VSS, even using two 1K resistors to simulate 50% pot.

    I switched to a 7805 supply and put back my "supposedly dirty" potentiometer. ADC low/high was back to a steady reading no matter where I turned the pot.

    I had code prepared using the techniques discussed in Melanie's ADC thread (or was it SORT, I don't remember). I got lost looking at the computational feature of the ADC in the 16F18877; that could have replaced my averaging routine and most likely reduced time.

    At worse if I get a dirty pot, I can drop the 1-2 lower bits from the 10-bit reading and still get 512-256 resolution out of a maximum 1024.
    Last edited by Demon; Yesterday at 03:35.
    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!

  21. #21
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,969


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    I did an extra test to confirm it wasn't another component on my main test board that was "messing up" the power.

    I powered my isolated PIC with that DC-DC converter and sure enough ADC was jumping between 546 and 569 using my pot.

    So now i have to find a 7805 variant that can supply 700mA without breaking a sweat.
    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!

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: How can I reduce ADC drift

    Drift is tottaly different than jumping numbers...

    When you said drift I assumed that you started with say 512 as a 50% of FSD and then it went up or down after some time, like 511, 510, 509 etc.

    Having random numbers sure can be due to crappy and noisy Voltage on Vdd.

    Ioannis
    Last edited by Ioannis; Today at 15:21.

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. SOLVED - How to calculate Timer preload
    By Demon in forum General
    Replies: 7
    Last Post: - 23rd August 2024, 18:33
  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. Hanging on SERIN2 - SOLVED!
    By blainecf in forum Serial
    Replies: 1
    Last Post: - 13th July 2006, 18:55
  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 : 8

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