A/D converter PIC16F1827


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    23

    Default A/D converter PIC16F1827

    i use this code but is not working

    Code:
    DEFINE ADC_BITS 10
    DEFINE ADC_SAMPLEUS 50
    'DEFINE ADC_CLOCK 3
    
    ADCON0  = %00000001
    ADCON1  = %01100011
    ANSELA = %00000111
    TRISA   = %00000111
    How to enable three channels (AN0,AN1,AN2) A/D converter PIC16F1827
    any help please

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    You've selected the FVR as reference for the ADC but I see no code that configures the FVR (it's disabled on POR).
    That's how far I got with what's shown.

    /Henrik.

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    ADCON1 = %01100011

    For your ADC Clock to = 3, ADCON1 must be %0011....

    You have the ADC Module looking at the FVR for a VREF+ (bits <2-0> of ADCON1). Nowhere in your listing do you mention setting up the FVRCON register so your ADC has its positive reference turned on. You might want to change ADCON1 to %00110000 and use Vdd for your VREF+.

    You can use the ADCIN command, ADCIN 0, VAR and PBP will automatically adjust ADCON0 to AN0 for you, or you can work it manually:

    ADCON0 = %00000011
    DO
    LOOP WHILE ADCON0.1 = 1. ;The GO bit
    VAR = ADRESH

    This gives you an 8-bit ADC value. For AN1, ADCON0 = %00000111, for AN2, ADCON0 = %00001011, and so forth.

  4. #4
    Join Date
    Sep 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    mpgmike Thank you very much
    Can you tell me how I will get a 10-bit price in the baty variable

    my programm
    Code:
    baty var word
    
    arxh:
    
    ADCON0 = %00000011
    DO
    LOOP WHILE ADCON0.1 = 1
    adcin 0,baty 
    
    if baty > 1050 then 
    gosub OK
    endif
    
    if baty < 1000 then 
    gosub noOK
    endif
    
    goto arxh
    Last edited by dovegroup; - 19th December 2017 at 09:02.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    Look from page 142 and after the details of the AD converter. It always makes a 10 bit conversion. It is up to you if you want 8 or 10 bits result.

    Anyway, having ADFM=1, the result is Right justified and stored in the ADRESH, ADRESL.

    So get your result in the baty variable as:

    baty.HIGHBYTE=ADRESH
    baty.LOWBYTE=ADRESL

    or

    baty.BYTE1=ADRESH
    baty.BYTE0=ADRESL

    In any case for the variable handling (e.g. baty.BYTE1, etc) look at the PICBASIC reference manual.

    Ioannis

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    You don't have to first do a "manual conversion" (via the GO/DONE bit) and then do a ADCIN (which basically does the same thing for you).
    If you're going to use ADCIN then add a DEFINE ADC_BITS 10. If you're going to use the "manual method" just do what Ioannis showed and get rid of the ADCIN command.

    And once you DO have your 10-bit resuly this won't work because baty will never be >1050 since the maximum result returned by the 10 bit ADC is 1023:
    Code:
    if baty > 1050 then 
    gosub OK
    endif
    /Henrik.

  7. #7
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: A/D converter PIC16F1827

    There are some 12-bit ADC Modules in a few of the PICs if you want better resolution. Referencing the ADMF = 1, that would be ADCON1.7 = 1. Let us know how you make out.

Similar Threads

  1. Replies: 3
    Last Post: - 22nd March 2013, 00:37
  2. A/D converter sample
    By allan josephus in forum mel PIC BASIC
    Replies: 5
    Last Post: - 23rd February 2008, 19:44
  3. Step up converter
    By Ron Marcus in forum Off Topic
    Replies: 1
    Last Post: - 27th July 2006, 20:44
  4. A/D converter
    By rocky79 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st October 2005, 06:40
  5. help D/A converter
    By matelda in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th September 2004, 17:25

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