Not sure if this will help (you probably already figured this out), but this PIC is
really nice. Here's an example of reading 4 x A/D channels simultaneously on a
18F2431.
Code:
DEFINE OSC 20
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0 ' 1 = inverted, 0 = true
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
DEBUG "A/D ch 1 = ",DEC CH1,13,10
DEBUG "A/D ch 2 = ",DEC CH2,13,10
DEBUG "A/D ch 3 = ",DEC CH3,13,10
DEBUG "A/D ch 4 = ",DEC CH4,13,10
PAUSE 5000
GOTO Main
END
Man, the more I play with this one, the more I like it.
Bookmarks