Using VREF pins for pots that don't reach ADC=0 or 255


+ Reply to Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    whether your pot is 4.7k or 5.2k should make zero difference , an adc reading of a pot is ratio metric
    if both pots are at 50% reading is vdd/2 no matter what the resistance is
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    Quote Originally Posted by richard View Post
    whether your pot is 4.7k or 5.2k should make zero difference , an adc reading of a pot is ratio metric
    if both pots are at 50% reading is vdd/2 no matter what the resistance is

    I set at 200ohm on multimeter to get more accurate reading:

    left pin to wiper = 2.5R
    right pin to wiper = 2.6R
    left to right = 4K7

    It doesn't go all the way down to 0, or up to 5K.

    ADC readings for this pot are 2 - 254 (I had removed 2 bottom bits).


    EDIT: I was using 20K setting for all readings before.
    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!

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


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    I went back and did same readings at 200 ohms on the other pot that had ADC from 0 - 255:

    left pin to wiper = 2.5R
    right pin to wiper = 1.9R
    left to right = 5.05K (at 20K ohms)
    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,644


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    10 bit adc with vref of 4.048 v = 3.95mV / step

    2.6 ohm/4700ohm * 5.00 v vdd = 2.76 mV

    the error does not match , your figures are out by 400%
    Warning I'm not a teacher

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    That 2.5ohms is just OK. You should read 0 or 255 at the ends of the pot.

    Ioannis

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    Quote Originally Posted by Demon View Post
    [U]...ADC readings for this pot are 2 - 254 ([I]I had removed 2 bottom bits...
    I'm an idiot. I thought I was being smart by ignoring any ADC variation under 3, turns out I was causing my own problem.

    Code:
        if ADCinput <> oldADC1 then
            ADCinput = ADCinput >> 2
            if ADCinput < oldADC1 then
                ADCdiff = oldadc1 - adcinput
            else
                ADCdiff =  adcinput - oldadc1
            endif
            IF ADCdiff > 2 THEN
                ...process ADC,,,
    ...

    If ADC falls on 1-2 or 253-254 as turned fully, it would never update when hitting 0 or 255.

    It was just random luck it was always THAT pot that did it, and not the 2nd pot.

    I should change my sig to:

    "I'm my worst enemy"
    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!

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


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    16F18855 with 5K pot


    So I have 2 rotary pots that refuse to go down to ADC=0. So I thought it was a perfect occasion to practice using Vref-.

    I've gutted my code so there's only 1 pot being scanned:

    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  ADC_SAMPLEUS 5              ' Set sampling time in uS
    
    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
    
    ;--- Setup registers -----------------------------------------------------------
    
    BAUDCON.3 = 1                       ' Enable 16 bit baudrate generator
    FVRCON = %0000000                  ' FIXED VOLTAGE REFERENCE CONTROL REGISTER
    ADCON0 = %10000100                  ' ADC CONTROL REGISTER 0
    '   bit 7   ADON: ADC Enable bit
    '               1 = ADC is enabled
    '   bit 2   ADFRM0: ADC results Format/alignment Selection
    '               1 = ADRES and ADPREV data are right-justified
    ADCON2 = %00000000                  ' ADC CONTROL REGISTER 2
    '   bit 2-0 ADMD<2:0>: ADC Operating Mode Selection bits(1)
    '               000 = Basic (Legacy) mode
    ADCLK = %00001111                   ' ADC CLOCK SELECTION REGISTER
    '   bit 5-0 ADCCS<5:0>: ADC Conversion Clock Select bits
    '               1111 = FOSC/32
    ADREF = %00010000                   ' ADC REFERENCE SELECTION REGISTER
    '   bit 4 ADNREF: ADC Negative Voltage Reference Selection bit
    '               1 = VREF- is connected to VREF- pin
    '               0 = VREF- is connected to AVSS
    '   bit 1-0 ADPREF: ADC Positive Voltage Reference Selection bits
    '               11 = VREF+ is connected to FVR_buffer 1
    '               10 = VREF+ is connected to VREF+ pin
    '               00 = VREF+ is connected to VDD
    WPUA = %11110011
    WPUB = %11111111
    WPUC = %00111111
    ANSELA = %00010111                      ' Pin A4 = ADC (B10K)  ...  not implemented
                                            ' Pin A3 = SW input 3
                                            ' Pin A2 = Vref-
                                            ' Pin A1 = ADC (B5K w/SW)
                                            ' Pin A0 = ADC (B5K)
    ANSELB = %00000000
    ANSELC = %00000000
    TRISA = %00011111                       ' Pin A4 = ...  not implemented
                                            ' Pin A3 = ...  not implemented
                                            ' Pin A2 = Vref-
                                            ' Pin A0 = ADC input 0
    TRISB = %00000000                       ' Pin B7 = ...not available, ICSPDAT
                                            ' Pin B6 = ...not available, ICSPCLK
    TRISC = %11000000                       ' Pin C7 = RX      *** Datasheet requirement, INPUT ***
                                            ' Pin C6 = TX      *** Datasheet requirement, INPUT ***
    SW                  var PORTA.3         '  ...  not implemented
    
    MsgData             var byte[3]
    MsgCode             VAR BYTE
    
    ADCinput            var WORD
    ADCcalc             var WORD
    ADCdiff             var WORD
    
    OldADC              var WORD
    OldADC0             var WORD
    OldADC1             var WORD
    
        Pause 1500                           ' Let PIC and LCD stabilize
    
        OldADC0 = 9999
    
        goto Mainloop
        
    ;--- Subroutines ---------------------------------------------------------------
    
    SendData:
        MsgData[0] = MsgCode   :   MsgData[1] = ADCcalc.byte1   :   MsgData[2] = ADCcalc.byte0
        hserout [   MsgData[0],    MsgData[1],  MsgData[2]   ]                             
        while TX1STA.1 = 0                                          ' Check TRMT bit
        wend
    
        oldADC0 = ADCcalc   
    RETURN
        
    Mainloop:
        
    rem                             ADC A0 test
        MsgCode = 0                                                 ' Record type
    
        adcin 0, ADCinput
        ADCcalc = ADCinput >> 2
        
        if ADCcalc < oldADC0 then
            ADCdiff = oldADC0 - ADCcalc
        else
            ADCdiff =  ADCcalc - oldADC0
        endif
    
        IF  ADCdiff > 2 then                                        ' Check for Diff over 2
            if ADCcalc <> oldADC0 then                               ' ADC value changed
                GOSUB SendData                             
            endif
        ELSE
            IF  ADCdiff > 0 then                                    ' Check for Diff over 0
                if ADCcalc = 0 then                                 ' Reached end of rotation
                    GOSUB SendData                             
                ELSE
                    if ADCcalc = 255 then                           ' Reached end of rotation
                        GOSUB SendData                             
                    endif
                endif
            endif
        endif
    
      GOTO Mainloop
    end

    I've added banks of caps on the wiper-to-VSS, as well as just before the VDD pin to the pot (0.1uF, 0.01uF and 0.001uF).

    I shift right only 2 digits and that seems to have stabilized things quite a lot; no noticeable jitter so far tonight. 256 seems like a workable range for me so far.

    The pot has a reading of 2.0mV when full right:

    Name:  1 Pot pin 0.jpg
Views: 5714
Size:  177.3 KB


    The Vref- pin reads at 15.7mV (used voltage divider 1K (0.985R really) / 3R:

    Name:  2 Vref-.jpg
Views: 5707
Size:  147.4 KB


    Pot 0 does not go below ADC=12,and is transmitted on the Saleae probe:

    Name:  3 Signals on Saleae probe.png
Views: 5662
Size:  12.4 KB


    And shows up nicely on LCD on 2nd PIC:

    Name:  4 Results on LCD.jpg
Views: 5660
Size:  31.5 KB


    I don't get it. I thought setting Vref- at 15.7mV meant that anything reading below that would read as 0...? I thought I was essentially raising the VSS lower range for ADC.

    Code:
    ADREF = %00010000                   ' ADC REFERENCE SELECTION REGISTER
    '   bit 4 ADNREF: ADC Negative Voltage Reference Selection bit
    '               1 = VREF- is connected to VREF- pin
    '               0 = VREF- is connected to AVSS

    I'm obviously missing something stupid again, but I don't see what. Or I totally misunderstood what Vref- does in life.
    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,644


    Did you find this post helpful? Yes | No

    Default Re: Using VREF pins for pots that don't reach ADC=0 or 255

    The pot has a reading of 2.0mV when full right:
    each adc step is 4.88mV therefore it should read zero

    you get a reading of 12 , after un-dividing by 4 that's a count of 48 or 0.234 volts
    it virtually has to be power supply noise.
    no amount of dicking around with reference voltage's is going to eliminate that much noise

    eliminate your power supply as the culprit by using 3x fresh AA batteries in its place
    Warning I'm not a teacher

Similar Threads

  1. ADC problem on 18F46K22 device using all 28 ADC pins
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd February 2012, 20:22
  2. MPXA4115A ADC vref set_up
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th August 2009, 19:04
  3. ADC Vref+ on PIC16F88
    By kblim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd December 2008, 10:14
  4. ADC Vref
    By srob in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th April 2008, 18:07
  5. 16F819 ADC 8bit=127, Not 255?Help!
    By Accelerator in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th June 2006, 17:34

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