ADC reading and configuration problem


Results 1 to 5 of 5

Threaded View

  1. #3


    Did you find this post helpful? Yes | No

    Default Re: ADC reading and configuration problem

    Quote Originally Posted by mark_s View Post
    Hello,

    I had the same problem a while back. The adcin command does not work with the
    pic18fxx31s. You have to read them manually. See this thread it may help.

    http://www.picbasic.co.uk/forum/show...ght=PIC18F2331
    Hi,

    I've tried this (from Bruce's code) :

    Code:
    DEFINE OSC 32      
    DEFINE LCD_DREG PORTC
    DEFINE LCD_EREG PORTD
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_EBIT 0
    DEFINE LCD_RSBIT 1
    DEFINE ADC_BITS 10
       
      CH1 VAR WORD
        CH2 VAR WORD
        CH3 VAR WORD
        CH4 VAR WORD
        
        ' Analog setup
        ' Single shot, multi-channel, simultaneous Mode2, Groups A+B, then C+D
        ADCON0 = %00011101
        
        ' Set +/- Vref to AVdd/AVss, FIFO buffer enabled
        ADCON1 = %00010000
        
        ADCON2 = %11001111   ' Right justified, 24 Tad, Frc
        ADCON3 = 0           ' Disable all triggers
        ADCHS = 0            ' Channel select for AN0,1,2,3
        ANSEL0 = %00001111   ' AN0,1,2,3 analog input, rest digital
     
    Main:
        ADCON0.1 = 1         ' Start the conversion
        WHILE ADCON0.1=1     ' Wait for it to complete (all 4 channels)
        wend
        
        ' FIFO buffer holds all 4 channels. Reading ADRESH & ADRESL automatically
        ' increments the buffer pointer (on read of ADRESL) to the next channels
        ' storage location.
        CH1.HighByte = ADRESH ' get result from AN0
        CH1.LowByte = ADRESL  ' Increment buffer pointer
        
        CH2.HighByte = ADRESH ' get result from AN1
        CH2.LowByte = ADRESL  ' Increment buffer pointer
        
        CH3.HighByte = ADRESH ' get result fron AN2
        CH3.LowByte = ADRESL  ' Increment buffer pointer
        
        CH4.HighByte = ADRESH ' get result from AN3
        CH4.LowByte = ADRESL  ' clears buffer pointer
      
       
        ' show 4 A/D channel results
        lcdout $fe,$2,DEC5 CH1," ",dec5 CH2
        lcdout $fe,$c0,DEC5 CH3," ",dec5 CH4
       
        pause 100
     
        GOTO Main
    The readings works, but the lower bits of the reading are unstable, and I don't know why.
    Last edited by pxidr84; - 27th March 2011 at 13:24.

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