PDA

View Full Version : 18F1320 ADC multiple channel select



jmgelba
- 28th November 2005, 20:23
According to the datasheet you have to select each channel as you want to read it using ADCON0. I want to be able to display 3 values at the same time an a 4x20 VFD. I presume I have to set it up where I change ADCON0 for each channel I want to read, then send to the VFD, go back, set ADCON for the next ADC channel and send that to the next line on the VFD etc etc.

Is there a simpler way to do this?

Here is a simple piece of code I wrote that reads a value and displays volts, the ADC count and junk to fill the other 2 lines.
ADCON1 selects which channels are set to analog inputs, and ADCON2 sets clock source and justification.
I want the value of ADCIN 4 on line 1, ADCIN 5 on line 2 and ADCIN 6 on line 3 with two words on the 4th line which will be above buttons on the front panel - kind of like a menu system.

OSCCON = $60 '4mhz
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
Define ADC_BITS 10
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50
Value VAR WORD
RAW VAR WORD
ADCON0 = %00011001
ADCON1 = %00001111
ADCON2 = %10111111
TRISA = %00000000
TRISB = %00010000

Pause 2000

loop: Lcdout $FE, 1
ADCIN 6, value
Raw = value
value = (value */ 500)>>2
Lcdout $FE, 2, "DC Volts= ",DEC (value/100),".",DEC2 value
Lcdout $FE, $C0, "ADC count= ",DEC RAW
LCDOUT $FE, $94, "Testing 3rd line"
LCDOUT $FE, $D4, "Testing 4th line"
Pause 250
Goto loop

BertMan
- 28th November 2005, 21:40
You do not need to set ADCON0. PBP controls this register via use of the ADCIN command.