ADC problems with a 16F1826 chip


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24

    Default ADC problems with a 16F1826 chip

    Hello all
    I'm trying to use a new chip to me, an 16f1826. I liked the idea of the 4.086 internal voltage reference. I wrote the test code below, trying to follow the datasheet. Unlike others, I've never had a problem using ADCIN so I am using it. The program compiles, loads and runs, but the display reads 00001, 00002 and 00003, depending on what my test pot is set to. Interestingly, it does correspond to 1, 2 and 3 volts input, but I'm assuming its coincidental since its a 10 bit register. The Microchip errata says that in my silicon version there is sometimes a flaw in the ADC circuit such that the "done" bit never comes true but I'm assuming thats not the problem because it does change its value and updates each cycle through. Any thoughts or comments would be appreciated.

    Take care

    Alec




    Code:
    '****************************************************************
    '*  Name    : 16f1826_test                                      *
    '*  Author  : alec noble                                        *
    '*  Notice  : Copyright (c) 2012 alec noble                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 8/31/2012                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
     #CONFIG
       __config _CONFIG1, _FOSC_INTOSC & _MCLRE_ON & _CLKOUTEN_OFF
       __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    
    #ENDCONFIG
    
    OSCCON = %01111010          '16 mhz internal clock, PLL off
    
    DEFINE OSC 16
    
    'define adc_bits = 10
    
    TRISA = %00000001           'RA0 input, all others output
    trisb = %00000001
    
    FVRCON = %11000011          'Fixed voltage reference on, comparator and output off, set to 4.096
    
    ANSELA = 1                  'AN0 analog, all others digital
    ANSELB = 0                  'all port B digital
    ADCON1 = %11100011          'right justified, clock = fosc/64, neg ref = Vss, pos ref = FVR
    
    ADC     var word
    txpin   var portb.0
    
    ADC = 0
    
    Pause 500                   ' let everything stabilize
    
    SEROUT2 txpin, 84, [24]     'turn serial LCD on
    
    main:
        ADCIN 0, adc
        SEROUT2 txpin, 84, [12]
        PAUSE 5
        SEROUT2 txpin, 84, [128,  dec5 adc]
        pause 250
        goto main

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: ADC problems with a 16F1826 chip

    Just change your define to all uppercase and no = sign..

    define ADC_BITS 10

    Without the correct define, PBP is still using 8-bits, and all you see are the top 2 bits when it's right justified (0-3).
    Last edited by Darrel Taylor; - 1st September 2012 at 17:02.
    DT

  3. #3
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: ADC problems with a 16F1826 chip

    Damn!!!

    Thanks Darrell - ebeer to you

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