adcin issues with 16f676


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171

    Default adcin issues with 16f676

    For some reason I can't seem to get this working, have played around for a couple of hours now and still no joy - I know it'll be in my setup somewhere - just cant find that vital point.

    Many thanks in advance for any input (I only know half of what I'm doing when I set up these registers)

    @ DEVICE PIC16F676, XT_OSC, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF


    Define OSCCAL_1K 1
    DEFINE OSC 4
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 2
    DEFINE ADC_SAMPLEUS 50


    TRISA = %000000
    TRISC = %101100

    ADCON0 = %10000001
    ADCON1 = %00010000
    ANSEL = %10000000 'enable ch7 analog
    VRCON = %10000000 ' A/D Voltage reference
    CMCON = 7 'Disable comparitor

    red var PortA.2
    green var PortC.0
    PDWN var PortC.1
    DAT var PortC.2
    pwr var PortC.4
    Switch var PortC.5

    batt var byte
    timeset var byte
    display var byte
    timer var word
    b0 var byte
    b1 var bit
    b2 var byte
    b3 var word

    clear
    timeset = 1
    PortA = 0
    PortC = 0

    Begin: 'start sequence
    adcin 7,batt
    red = 1 'turn red led on
    if batt > 10 then green = 1 'turn green led on
    if batt > 50 then red = 0 'turn red off
    pause 500
    goto begin

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    This reply is how I read the ADC in a 16F876A. I guess the registers and the reading would be the same in the 16F676, but I haven't read the datasheet and can't vouch for it.

    Code:
    Scanspeed   var word    ' this is where we read the ADC value
    
            ADCON0.2 = 1      ' Start conversion
            while ADCON0.2    ' wait till conversion is done
            wend
            ScanSpeed.HighByte = ADRESH
            ScanSpeed.LowByte = ADRESL
    Also, you need to heed this warning (from the PBP manual)
    Code:
    Before ADCIN can be used, the appropriate TRIS register must be set to
    make the desired pins inputs.  ADCON1 also needs to be set to assign
    the desired pins to analog inputs and in some cases to set the result
    format and clock source.

    Hope this helps
    Jerson
    Last edited by Jerson; - 5th November 2007 at 03:43. Reason: Warning note added

  3. #3
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Hey thanks for that - but i ended up deleting my adcon and vrcon registers and let pbp do it for me and it all worked yay

Similar Threads

  1. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 20:27
  2. ADCIN Problem
    By JavPar in forum General
    Replies: 33
    Last Post: - 20th January 2009, 03:36
  3. ADCIN problems with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 26th July 2007, 11:38
  4. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07:46
  5. PIC12F675 and ADCIn
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th February 2005, 07:42

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