12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct value


Results 1 to 18 of 18

Threaded View

  1. #2


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Here are some snippets of code from a project of mine using a PIC18F45K80. I think you should remove this section from your code. When not using adcin, I prefer to manually set the adc registers.

    Code:
     '----------------------------------------------------------------------------------------
     'Define the Analog to Digital conversions
     DEFINE ADC_BITS 12 '12-bit resolution
     ' DEFINE ADC_CLOCK 5 'Set clock source to Frc/16
     DEFINE ADC_CLOCK 6 'FOSC/64, 0.8uS @ 64Mhz
     DEFINE ADC_SAMPLEUS 50 'Sample time in uS before A/D conversion is started
    
     '-----------------------------------------------------------------------------------------
    Maybe something here will help you get it running.
    Code:
    'ADC-----------------------------------------------------		    
    ADCON0 = %00000001 ' A/D module enabled
    ADCON1 = %01110000 '%01110000 Vref = INT 4096, TRIG ctmu, NEG REF VSS
    ADCON2 = %10010100 ' Right justified, 12 Tad, Frc clock
    ANCON1 = %00000000  'Select Digital or Analog AN8 - AN14
    
    '-------------------------------------------------------------
    TRISA = %00000011
    
    ADC_AN0   var word
    ADC_AN1   var word
    
    
    '=======================================================================
    GET_AD0:
    ADCON0 = %00000001      'AN0 ENABLED
               ADCON0.1 = 1
    @   nop 
    @   nop
    @   nop 
    @   nop
    @   nop 
    @   nop
    @   nop 
    @   nop           
        WHILE ADCON0.1 = 1       ' A/D complete?
    @   nop 
    @   nop     
        WEND
    ADC_AN0.lowbyte =ADRESL
    ADC_AN0.highbyte = ADRESH
    '===================================================================
    GET_AD1:
    ADCON0 = %00000101      'AN1 ENABLED
               ADCON0.1 = 1
    @   nop 
    @   nop
    @   nop 
    @   nop
    @   nop 
    @   nop
    @   nop 
    @   nop           
        WHILE ADCON0.1 = 1       ' A/D complete?
    @   nop 
    @   nop     
        WEND
    ADC_AN1.lowbyte =ADRESL
    ADC_AN1.highbyte = ADRESH   
    
    '===================================================================
    Last edited by mark_s; - 8th May 2014 at 21:39.

Similar Threads

  1. How do I use 10 bit A/D on 8 bit Pic? 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2020, 21:10
  2. Replies: 1
    Last Post: - 13th March 2012, 00:34
  3. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 23:18
  4. LCDOUT 4-bit data on 8-bit setting
    By breesy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th June 2006, 19:39
  5. Help 14-bit and 16-bit Core
    By jetpr in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th September 2005, 04:29

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