PDA

View Full Version : Help needed with 16F870 ADC



srob
- 10th May 2008, 12:16
I am trying to measure a voltage between 2.90V and 4.12V (from a RTD via a differential amplifier[MCP602]), and display this as a number between 0 and 1023.

My circuit has this voltage on AN0, and 2.9V on -Vref(AN2) and 4.12V on +Vref(AN3)

The programme is:

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 1
DEFINE ADC_SAMPLEUS 100

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

ADCON1=%10001000 '+Vref, -Vref, right justified
TRISA=255 'PortA analogue input

PT100 var porta.0
avg var word
temp var word
temp1 var byte
sign var byte
cnt var byte

cnt=0
avg=0

PAUSE 500
LCDout $FE,1 'clear LCD
LCDout "Temperature ="

main: ADCin PT100,temp
avg=avg+temp
cnt=cnt+1
pause 100
if cnt>3 then main

cnt=0
temp=avg/3
avg=0

LCDout $FE,$C0,DEC temp," "
goto main

Doesn't seem to work though, ADC reads 0! Looked though 16F870 datasheet, but can't see what I'm missing?

Acetronics2
- 10th May 2008, 13:14
Hi,

Instead of " PT100 var PORTA.0" ...

just write

PT100 CON 0 ...

Alain