ADC setup on 12F1822 ??


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    16

    Default ADC setup on 12F1822 ??

    Hello!

    Has anyone been successful on getting data from the ADC on a 12F1822? While I can get 8-bit conversions, I cannot get 10-bit results. I have puzzled through the related registers from reading the data sheet. Briefly, I find that setting ADCON1.7 stops the ADC from working. Clearing ADCON1.7 lets it work in 8-bit mode.

    Reading the errata sheet they show problems with the ADC, and a possible workaround, but I'm not convinced that is my problem since the problem also occurs on a 12F1840.

    I can post example code, but initially I just wanted to know if someone on the forum is able to get 10-bit data from a 12F1822, or a 12F1840.

    Thanks!

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    works for me
    Code:
    #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_OFF
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_OFF
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    ADCON1=$f0      'rc clk vdd ref   right justify
          osccon=$6A    '4 mhz
          anselA=1       'dig i/o
            ' CMCON0=7        ' compare off 
          trisA=001
          
      adval var word    
      main:
      pause 5  
       ADCIN 0, adval
     lata=0
     
     if adval > 500 then lata.2= 1 'led1
     if adval> 200  then  lata.1=1' led2
      
      goto main

  3. #3
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    Thanks ^^^
    I am doing the same register setups as you show, except that I'm using AN2 (ANSELA=%0100, TRISA=%01100). In addition I have ADCON0.0=1 (enable ADC). I'll try removing this. I'll work on this and post my results.
    Thanks again!

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    ADCON0.0=1 serves no purpose the ADCIN code will do that for you

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    This may be obvious but since you didn't post your code I'll say it anyway.
    The variable you're putting the result in is declared as a WORD, right?

    /Henrik.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    looks like "Occam's Razor" may have struck again

  7. #7
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: ADC setup on 12F1822 ??

    Quote Originally Posted by HenrikOlsson View Post
    ... The variable you're putting the result in is declared as a WORD, right? /Henrik.
    Yes, it's a WORD. But thanks!

Similar Threads

  1. Help to setup ADC for 16F1826
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th February 2014, 00:06
  2. 12F1822 troubles
    By Charlie in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th June 2012, 12:53
  3. 12F1822 embedded host?
    By dhouston in forum USB
    Replies: 5
    Last Post: - 18th September 2011, 18:14
  4. MIBAM and 12F1822...
    By alesniak in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 17th September 2011, 06:45
  5. ADC setup for 16F716
    By droptail in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th November 2009, 02:39

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