configuring AD converter in a 12F615


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    That would be awesome Darrell!

    I have something working now using a 1N914 diode from the pin to ground and a 10K to plus from the pin. Sorta using the diode as a reference. But it's depending on the diode drop which may not be accurate in production.

    A no-pin solution would be a better design. Have you posted this idea to the forum in the past? If not I'm sure that many of us that design battery powered products would benefit from your genius!
    "Do or do not, there is no try" Yoda

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


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    Yes, I had posted it before. But it was for a different chip, and I can't find it now.
    It's not too difficult, so I re-wrote it for the 12F615 and tested it on a LAB-X4.

    The idea is to use the internal 0.6V reference (ADC channel 5).
    The reference stays the same as VDD changes, so with VDD as the ADC's Vref, the value read changes too. You can use that change to calculate actual VDD without needing an external Analog Pin.

    Code:
    DEFINE ADC_BITS 10
    
    LCD       VAR GPIO.1              ; serial pin for LCD
    LCDbaud   CON 396                 ; serial baud rate
    
    ADval     VAR WORD
    VDD       VAR WORD
    
    ANSEL  = 0                        ; All Pins are Digital
    ADCON0.7 = 1                      ; Right Justify A/D result
    HIGH LCD : PAUSE 2                ; Initialize serial data level
    
    SEROUT2 LCD,LCDbaud,[$FE,1] : PAUSE 3 ; Clear LCD
    
    GOSUB GetVDD
    
    SEROUT2 LCD,LCDbaud,["A/D=",DEC ADval,"  ", _
                         "VDD= ",DEC VDD/10,".",DEC1 VDD]
    STOP
    ;------------------------------------------------------------------
    Vref_AD   CON 117           ; A/D reading for 0.6V Vref @ 5V VDD
    
    GetVDD:
        VRCON.4 = 1                   ; Enable 0.6V Fixed reference
        PAUSE 10                      ; allow reference to stabilize
        ADCIN 5, ADval                ; read the 0.6V reference
        VDD = (Vref_AD * 50) / ADval  ; convert to volts
        VRCON.4 = 0                   ; turn off fixed reference
    RETURN
    The VDD result has 1 decimal place, so 5.0V will be 50.

    HTH,
    DT

  3. #3
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    Awesome Darrell!

    I plugged in your brilliant code and it works flawlessly!

    Is it possible to get 2 decimals of resolution using the 10bit ADC? On a 3 Volt system that drops out a 2.0 Volts it could make a difference.
    "Do or do not, there is no try" Yoda

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


    Did you find this post helpful? Yes | No

    Default

    Well as far as the math goes, you can get 2 decimals by multiplying *500 instead of 50. Then change the SEROUT2 to divide by 100 and use DEC2.

    But those references aren't really accurate enough to get that kind of resolution reliably.
    And they drift some with temperature, so you'll probably want to stick with 1 decimal place.

    You could also do the same thing with an external "Precision" reference and get better resolution. But of course that uses a PIN, which are precious on an 8-pin chip.
    DT

  5. #5
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    Yeah, I though that would work. I tried X500 and got readings that varied by about .05 Volts even when I hit the PIC with a heat gun to see if there would be significant temperature drift. Not bad actually.

    This is a totally awesome way to read the battery voltage Darrell. THANKS AGAIN. You are a friggin genius!
    "Do or do not, there is no try" Yoda

  6. #6
    klantz12's Avatar
    klantz12 Guest


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    Can anyone help me with configuring the AD converter in 16F877A on the labX1 board? I am using MicroCode Studio-pbp and i have tried the following code from the help button and from another post i read.


    ADCON1=132 ' 128 + 4 = %10000100 'Left just 3 analog inputs rest digital
    TrisA = 255 'all inputs for the a to d
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (rc = 3)
    Define ADC_SAMPLEUS 50 ' Set sampling time in microseconds

    AdcIn 1, W0
    AdcIn 3, W1


    The error says that ADCIN needs a variable.

    My assignment is just to read the AD input from the three potentiometers at A0 A1 and A3.

    Pretty lost. Thanks! also, i didnt know how to start a new thread so sorry for posting in ya'lls.

    Kay

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    didnt know how to start a new thread so sorry for posting in ya'lls.
    Big button near the top of forum pages, "+ Post New Thread".
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: configuring AD converter in a 12F615

    AdcIn 1, W0
    AdcIn 3, W1

    The error says that ADCIN needs a variable.

    Kay, I'm assuming that you have migrated to the PIC world from Basic Stamps and you may not have defined your variables - something you do not need to do in Stamps. So you need:

    W0 var byte

    to define W0 as a byte variable - these definitions usually go near the top of the page.
    "Do or do not, there is no try" Yoda

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts