Need some help with ADC readings on 16F72


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Default Need some help with ADC readings on 16F72

    My code is as follows:
    Code:
    Include "modedefs.bas"
    DEFINE OSC 20       ' OSCCON defaults to 4MHz on reset
    DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    
    ;-------------CONFIGURATION FUSES SET HERE-------------------------
    @ __Config _RC_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON ; & _CP_ALL
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    
    PAUSE 100
    ;------------REGISTERS SET HERE------------------------
      ADCON1=%00000100
      ADCON0=%1100000
      PORTA=0
      PORTB=0
      PORTC=0
      TRISA = %000001
      TRISC = 0
      TRISB = 0
      OPTION_REG = %10001111  ' RAPU = off, PS 1:256 to TMR0
      PORTA=0
      PORTC=0
      PORTB=0
    
    B0 Var Word
    gosub CLER
    start var Adcon0.0
    done var Adcon0.2
    
    Main:
    Start=1
    while done=1 : pause 1 : wend
    b0=ADRES
    LCDOUT $FE,2," B0=",dec3 B0 : pause 500
    GOSUB CLER
    goto Main
    
    cler:
    		LCDOUT $FE,1
    		pause 10
    		LCDOUT $FE,2
    		PAUSE 10
    		LCDOUT $FE,$0C
    		pause 100
    
    return
    I am trying to take adc reading of a POT, but the result is constantly "B0=010" on my LCD. Could someone help me identify the problem please?

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


    Did you find this post helpful? Yes | No

    Default Re: Need some help with ADC readings on 16F72

    Change ADCON0=%1100000 to ADCON0=%11000000, and _RC_OSC to _HS_OSC.

    Also, you don't need a word variable for an 8-bit result.
    Last edited by Bruce; - 28th August 2011 at 12:00.
    Regards,

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

  3. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Need some help with ADC readings on 16F72

    Thanks Bruce. Please clear my 1 doubt which I always had but I never asked, but now since I cannot figure out the difference myself, here it goes:

    Q) What it the difference between ADCON0 registers BIT 5-3 & ADCON1 BIT 2-0?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Need some help with ADC readings on 16F72

    Datasheet is quite self explanatory

    ADCON0 bit 5-3 CHS<2:0> Analog Channel Select Bits
    This will select the Analog Channel (I/O) to read (ADCIN 0, Var , ADCIN 1, Var)

    ADCON1 Bit 2-0 PCFG<2:0> A/D Port Configuration Control Bits
    This configure the I/O... Digital OR Analog
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

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