16F88 ADC Problems


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2011
    Posts
    16

    Red face 16F88 ADC Problems

    Hi guys, I'm new to this. I'm trying to get my PIC 16F88 to read in analogue on RB6 & RB7 and strobe a LED on RB2. I can get the LED to light up but it appears that the ADC is not reading in any values. I'm having problems configuring the ADC. Please help !!!

    I have included the main part of my program below.....

    Thanks

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

    define OSC 20 '20MHz Must set Osc to HS when programming not XTL
    '
    ' Set CONFIG1: --11 1111 0110 1110
    ' Set CONFIG2: ---- ---- ---- --11
    '
    INCLUDE "modedefs.bas" ' Include for SEROUT command
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 1 ' Set clock source, not sure if this is correct
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    ' Set ADC Registers
    TRISB = %11111011 ' 1=In, 0=Out
    ANSEL = %01111111 ' 1=Analogue, 0=Digital
    ADCON0 = %10111000 ' Configure and turn on A/D Module.
    ADCON1 = %10000000 ' Right Justify A/D result
    ADCIN PORTB.6, Accel ' Read channel 5 to Accel
    ADCIN PORTB.7, Gain ' Read channel 6 to Gain
    pause 1000
    serout 2,N9600,["g = ", #Accel," gain = ", #Gain,10,13]
    high PORTB.2 'drive LED high


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

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


    Did you find this post helpful? Yes | No

    Default Re: 16F88 ADC Problems

    ADCIN must use the ADC channel number, not it's pin name

    ADCIN 5, Accel ' Read channel 5 to Accel
    ADCIN 6, Gain ' Read channel 6 to Gain
    Steve

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

  3. #3
    Join Date
    May 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: 16F88 ADC Problems

    Thanks Steve, but how does the ADC know which port to read in? For example, we could read in PortA.1 or PortB.1

    cheers

    Mark.

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


    Did you find this post helpful? Yes | No

    Default Re: 16F88 ADC Problems

    It's all about it's associated Channel number.

    PortB.0.= AN0 = Channel 0 = ADCIN 0, bVar
    PortB.7 = AN6 = Channel 6 = ADCIN 6, bVar

    PBP manual:

    ADCIN

    ADCIN Channel,Var

    Read the on-chip analog to digital converter Channel and store the result in Var. While the ADC registers can be accessed directly, ADCIN makes the process a little easier
    Manual Really said Channel... not pin name.

    Further details, open the datasheet, and see how you manually implement it... you also select/assign a channel number to the PIC register, not a pin name.


    hth
    Last edited by mister_e; - 15th June 2011 at 02:15.
    Steve

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

Members who have read this thread : 0

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