Stable ADC readings


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Just include an RC filter on the A/D input, and put the PIC to sleep just before enabling the A/D conversion. This returns very stable readings in most applications with a stable power supply or Vref.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Nice subject !
    I use a similar code for reading the over-current of one DC motor :
    Code:
    check:           
     vt  =0
     vs  =0
     grup=0
     cnt =0
     pause 50					
     for cnt = 1 to 10
     	adcin 3, adval
     	vt=adval * 5000
     	vt=div32 1023
     	grup=vt+grup
     	pause 5
     next cnt
     vs=grup / 10
          if (vs > checkin) or (T1Count > 50) then 		   
      	     	gpio.0=0
               	gpio.5=0
          endif
    If the averge of 10 readings it's bigger than checkin value (or time exceed 5 seconds) then gpio.0 and gpio.5 goes low.
    It's one good ideea to use ADCON instead ADCIN ? How to do this and keeping average of 10 readings ?

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Need advice, please !

    It's this correct ?
    In header of code I add :
    Code:
        ADCON0 = %10001101      ' ADC input on GPIO.4/AN3/pin3 (page 41)
                                ' MSB 1 = Right Justify                   "1"    
                                '     0 = Vdd as voltage reference        "0"
                                '     0 = n/a                             "00"
                                '     0 = n/a
                                '     1 = select channel 03 (bit 2 of 2)  "11"
                                '     1 = select channel 03 (bit 1 of 2)
                                '     0 = conversion status (see routine) "0"
                                ' LSB 1 = A/D converter module is on      "1"
    And I modify the "check" subroutine like that :
    Code:
    check:           
     vt  =0
     vs  =0
     grup=0
     cnt =0
     pause 50			
     for cnt = 1 to 10
          ADCON0.1 = 1
          NOT_DONE:
    		if ADCON0.1 = 1 THEN NOT_DONE
                Pause 10
                adval.highbyte = ADRESH
                adval.lowbyte = ADRESL
     PAUSE 10
     	vt=adval * 5000
     	vt=div32 1023
     	grup=vt+grup
     PAUSE 10
     next cnt
     vs=grup / 10
          if (vs > checkin) or (T1Count > 50) then 		   
      	     	gpio.0=0
               	gpio.5=0
          endif
    The hardware it's in picture.
    Thanks !
    Attached Images Attached Images  

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    I've tested the code ; it's OK.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    I've used ADCIN pretty much from day one, but I noticed I was getting some *very* jittery readings (255,243,246,255,243,246 etc)...I couldn't get to the bottom of it (spent a good while trying the usual stuff), I'd forgot about this thread but thankfully foiund it with Google)

    It's the first time I've used the manual ADC method......but I'm pleased to also report my ADC readings are now solid as a rock.

    Just for the record, here's what I used on my 12lf1822 (I'm only using 8 dits ADC)...

    Code:
    ADCON0 = %00000100     ' select ch1 (AN1 Pin 6)
    ADCON1 = %00000000     'set ADC +ve reference to VCC 
    ' 
    main:
    gosub Do_ADC
    pause 100
    hserout [DEC ADC_RESULT,13,10]
    goto main
    ' 
    'ADC sub routine...
    Do_ADC:
    PAUSEUS 50              ' Wait for A/D channel acquisition time
    ADCON0.1 = 1           ' Start conversion
    WHILE ADCON0.1       ' Wait for it to complete
    WEND
    ADC_Result = ADRESH
    return
    Many thanks to you all on this thread...I shall never go back to the ADCIN method!
    Last edited by HankMcSpank; - 26th June 2011 at 18:52.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    I wish the edit feature was open longer - I forgot to turn the ADC on above, sohere's the correction....

    Code:
    ADCON0 = %00000101     ' select chan1 (AN1 Pin 6), turn ADC On Bit 0




  7. #7
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Hello,
    i made this to programm ADC

    bmf_comm1 VAR PORTB.0
    bmf_comm2 VAR PORTB.1
    'Variables
    bmfsD VAR WORD
    bmfs1D VAR WORD
    iled var byte
    blink1 var byte 'pour clignotement 1ère led
    blink2 var byte 'pour clignotement 2ème led
    'configuration du port pour lire l'entrée analogique
    TRISA = %00000011 ' RA0 et RA1 en entrée
    TRISB = %11111100 ' RB0 et RB1 en sortie
    ADCON1 = $10000010 'RA0 à RA3

    test_depart:
    Low bmf_comm1
    Low bmf_comm2
    High bmf_comm1
    high bmf_comm2
    pause 2000
    goto mainloop
    'lecture de la valeur
    getad:
    PAUSEUS 50 ' Wait for A/D channel acquisition time
    ADCON0.2 = 1 ' Start conversion
    WHILE ADCON0.2 ' Wait for it to complete
    WEND
    Return

    ' Subroutine to get pot x value
    getx:
    ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
    Gosub getad
    bmfsD = ADRESL + (ADRESH*256)
    Return

    ' Subroutine to get pot y value
    gety:
    ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
    Gosub getad
    bmfs1D = (ADRESH*256) + ADRESL
    Return
    val_leds:
    low bmfs_comm1
    low bmfs_comm2
    gosub getx
    gosub gety

    if (bmfsD > 1000) Then Goto val_leds
    if (bmfsD > 750) Then Goto boucle_led
    if (bmfsD > 500) Then Goto boucle1_led
    if (bmfsD > 250) Then Goto boucle2_led

    High bmf_comm1
    High bmf_comm2
    pause 1500
    goto val_leds
    boucle_led:
    iled = 0
    while iled < 5
    if iled = 1 or 3 or 5 then high blink1:low blink2
    if iled = 0 or 2 or 4 then low blink1:high blink2
    iled = iled + 1
    pause 1000
    wend
    goto val_leds
    boucle1_led:
    High bmf_comm1
    low bmf_comm2
    pause 3000
    goto val_leds
    boucle2_led:
    low bmf_comm1
    high bmf_comm2
    Goto val_leds
    End

    The leds works but always lightning , action on button (RB0 only for the moment) don't change anything.
    No blinking .
    I don't know what .
    thanks.

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