
 Originally Posted by 
mark_s
					 
				 
				
			
		 
	 
 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.
				
			
Bookmarks