Maker Pro
Maker Pro

PIC18F A/D

R

Randy Day

Jan 1, 1970
0
Well, I must be missing something obvious in the
docs. I can't get the ADC stuff working on my
PIC18F2455. The simulator steps through it, but
the micro doesn't seem to read anything.

Oh, yeah, what clock speed am I setting in the
config section? The code that does run seems
slower than it did on the learning devices.

Thanks for any hints, advice, pointers, etc.

Here's the relevant portions of the code:

;setup/initialization
#include <p18F2455.inc>
config LVP = off
config XINST = OFF
config CPUDIV = OSC1_PLL2
config PLLDIV = 1
config WDT = OFF
config MCLRE = OFF
config DEBUG = OFF
config PBADEN = ON ; need lots of a/d inputs
config LPT1OSC = OFF
config FOSC = INTOSCIO_EC

BSF ADCON2,5 ; set Tad = 8
BSF ADCON2,2 ; Fosc/4

MOVLW 0x03
MOVWF ADCON1 ; set vrefs (internal), AN0-AN11 on


ADCREAD
MOVWF ADCON0 ; set A/D to channel defined in WREG
CALL ONE_US
CALL ONE_US
CALL ONE_US ; wait 5us for A/D to settle
CALL ONE_US
CALL ONE_US
BSF ADCON0,0 ; start conversion
BTFSC ADCON0,1 ; this bit will change to zero when the conversion is
complete
goto $-2

BCF ADCON0,0 ; turn off A/D
RETURN

; in the main program
MOVLW 0x00 ; tell ADC to read AN0
CALL ADCREAD
 
M

Mark Fortune

Jan 1, 1970
0
Randy said:
Well, I must be missing something obvious in the
docs. I can't get the ADC stuff working on my
PIC18F2455. The simulator steps through it, but
the micro doesn't seem to read anything.
------------8<-----------------------8<-----------


BCF ADCON0,0 ; turn off A/D
RETURN

; in the main program
MOVLW 0x00 ; tell ADC to read AN0
CALL ADCREAD

I dont know an awful lots about the 18F2455, in fact i've only just
learnt how to program the 18F1320. Altho I cant see where you are
reading the ADC, is it stored in its own special register like the 1320
(which uses ADRESH:ADRESL). One thing I did notice about the 1320 is
that if I turned the ADC off before reading ADRESx into a register I
often got wierd results... maybe it's the same for the 2455?

Mark
 
R

Randy Day

Jan 1, 1970
0
Mark Fortune wrote:

[snip]
I dont know an awful lots about the 18F2455, in fact i've only just
learnt how to program the 18F1320. Altho I cant see where you are
reading the ADC, is it stored in its own special register like the 1320
(which uses ADRESH:ADRESL). One thing I did notice about the 1320 is
Yes.

that if I turned the ADC off before reading ADRESx into a register I
often got wierd results... maybe it's the same for the 2455?

Hmm. I hadn't considered that; I just treated
ADRESx as normal registers, and let other
routines read from it. I'll try transferring
them before turning it off.
 
Top