I have been trying to figure out how to use the
ADCIN command with the PIC18F2431 or PIC18F4431.
My problem is using more than one channel. I can get AN0
to work or AN1. But not togeather. It may be that the results are stored
in the fifo, which ADCIN does not address?
If anybody knows how to use the ADC in these chips. With or without adcin and
can share that would be great.
I just want to read some pots on AN0 and AN1, nothing fast.
Thanks
Mark
code
'************************************************* ***************
'* Name : ADC TEST PIC18F2331 - 4431 *
'* HIGH SPEED ADC AND PBP *
'* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/24/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
DEFINE OSC 20
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
DEFINE LCD_DREG PORTD '
DEFINE LCD_DBIT 0 ' STARTING BIT LCD PORTD.0 TO PD.3
DEFINE LCD_RSREG PORTD ' PORTD RS REGISTER
DEFINE LCD_RSBIT 4 ' LCD RESET PORTD.4
DEFINE LCD_EREG PORTD ' PORTD E REGISTER
DEFINE LCD_EBIT 5 ' LCD ENABLE PORTD.5
DEFINE LCD_BITS 4 ' 4 BIT INPUT VS 8 BIT
DEFINE LCD_LINES 4 ' LCD DISPLAY LINES
TRISA =%00011111
LATA =%00000000
TRISB =%00001111
LATB =%00000000
TRISC =%00000001
LATC =%00000000
TRISD =%00000000
LATD =%00000000
TRISE =%00000010
'AD REGISTERS
ADCON0 = %00000001 'AD ENABLED
ADCON1 = %00010000 'VREF = RAILS,FIFO
ADCON2 = %00111001 'LEFT JUSTIFIED, 16 TAD, FOSC/8
ADCON3 = %11000000 'AD INTERUPTS & TRIGGERS DISABLED
ADCHS = %00000000 ' ENABLED CH AN0,AN1,AN2,AN3
ANSEL0 = %00000011 'Select Analog channels AN0:AN2
ANSEL1 = %00000000 'Not used with PIC18F2331, 2431
'ADPNT ????????????? NEED TO POINT PROPER FIFO REG FOR RESULTS???
ADC_AN0 var word
ADC_AN1 var word
MAIN:
PORTE.0 = 1
ADCIN 0,ADC_AN0
ADCIN 1,ADC_AN1
PAUSE 200
PORTE.0 = 0
'4X20 LCD DISPLAY AD RESULTS AN0, AN1
LCDOUT $FE, $80, "PIC18F2431 ADC TEST "
LCDOUT $FE, $C0, "AN0 ",DEC4 ADC_AN0," "
LCDOUT $FE, $94, "AN1 ",DEC4 ADC_AN1," "
LCDOUT $FE, $d4, " "
PAUSE 200
GOTO MAIN
END
/code
Bookmarks