I have a little pic project goine here - e v e n t u a l l y!
The one fly in the ointment is a temprature routine, in which my A/D doesn't
make sense, but returns a value of 3ff for the 10 bits :-(
The pic (a 16f877) is grounded to the - side of a -1.5V battery. Vref- is to
the positive side of the -1.5V battery. Vref+ is exactly 1.2V above that. My
temprature signal comes in at -Vref +0.25V for 25 degrees C - I should get a
reading of ~ 0x0d5 (0.25 / (1.2 /1024)). I flashed another configuring the
pic to use a 5V reference. My reading this time should have been ~(1.75 /
(5/1024)) or 0x166; This time I saw 000 for the 10 bits. Here's the code I'm
using in order of it should appear (I've not shown the bank change
instructions, but they're there). Spot the gotcha? I don't. The resolving
code simulated fine.
; INIT stuff
clrf PORTA ; clears data latches.
clrf ADCON0 ; Sets a/d, but off
movlw 0x41 ; W=0100 0001
movwf PIE1 ; Bank1: Sets timer1 & adc as int. sources
clrf TRISA
movlw 0x1f ; W= 0001 1111
movwf TRISA ; PORTA = 5 inputs
movlw 0x8c ; W=1000 1100
movwf ADCON1 ; Bank1: Sets 3 a/d &2 ref inputs
clrf ADRESL ; clears low result byte of adc
bsf ADCON0, 0 ; Turns A/D on, but idle.
clrf ADRESH ; Clears high result byte of a/d
bsf INTCON, PEIE ; enables Peripheral interrupts. Globally disabled
still
bsf INTCON, GIE ; Turn on global interrupts.
; To Start a conversion
bsf ADCON0, 2 ; Starts A/D Conversion on RA0
; This responds with an interrupt
btfsc PIR1, ADIF ; A/D interrupt?
call ADC ; Call temperature routine
; And finally
bcf PIR1, ADIF ; clears ADC interrupt signal
The processing routine dumps ADRESL to 0x72 which is readable from all bamks,
then goes back to Bank 0 for sorting out the display of data.
--
Regards,
Declan Moriarty
Applied Researches - Ireland's Foremost Electronic Hardware Genius
A Slightly Serious(TM) Company
Without the optimist, the pessimist wouldn't know how happy he isn't
--
Author: Declan Moriarty
INET: [EMAIL PROTECTED]
Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB CHIPDIR-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).