16F1826 ADC setup help!


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    50

    Default 16F1826 ADC setup help!

    Help! I have this code:

    Code:
    ;----[16F1826 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1826"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ;INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _PLLEN_OFF             ; 4x PLL disabled
    cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    cfg2&= _BORV_HI               ; Brown-out Reset Voltage (Vbor), high trip point selected.
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    OSCCON = %01101010          '4 Mhz internal clock, PLL off
    DEFINE OSC 4
    
    DEFINE ADC_BITS 10 ' 10 bit A/D Conversion
    DEFINE ADC_CLOCK 4
    DEFINE ADC_SAMPLEUS 50 ' 50 uS A/D sample time
    
    PORTA = 0
    PORTB = 0
    TRISA = %00000101 'Set A.0 and A.2 as input, all else Outputs
    TRISB = %00000000 'All Outputs
    ADCON0 =%00001001 'Turn ON ADC
    ADCON1 =%11110000 'Right justified, Internal R/C
    
    ANSELA =%00000100 ' AN2 on PortA.2 Analog
    ANSELB =%00000000 ' Digital I/O 
    
    adval var word
    
    adcin 2, adval
    I have not shown the mainloop, but it is essentially reading the ADC with

    Code:
    adcin 2, adval
    I cannot get this ADC to work. I need it to read a 0-5V on RA.2.

    I am wanting to use the INTERNAL oscillator @ 4Mhz.

    I have tried for hours. What am I missing please?
    Thanks!

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 ADC setup help!

    What version of PicBasicPro are you using ?

    Also, by not including all the code, it's like saying you have all the ingredients but not telling us the recipe and then asking people why you cake won't rise !

    I'm no expert, but you seem to be setting up ANSEL and ADCON so it's not as if all ports are digital or something like that is the cause, so it could possibly be something in the main part of the code which ou haven't shown.

  3. #3
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 ADC setup help!

    Thanks for your response Scampy!
    I was just wanting to use simple code to get the ADC to work. With the help of Richard's code (from the MELABS forum) I was able to get the ADC to work. Thanks to your help I re-looked at the rest of my code, and I found the issue. I had set PortA.2 to an output later on (by mistake!).

    So, all is working PERFECTLY now!!!!

    Thanks again!!
    Russ :-)

Similar Threads

  1. ADC setup on 12F1822 ??
    By swr999 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st October 2014, 00:06
  2. Ports interacting?? 16F1826
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 14th February 2014, 19:22
  3. Help to setup ADC for 16F1826
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th February 2014, 00:06
  4. ADC problems with a 16F1826 chip
    By alec in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2012, 22:09
  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 : 1

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