Hello everyone,
I have read that the 10bit reading from the onboard ADC on the 12F675 should range from 0 to 1023 (1024 steps). I can never achieve this. I have tried two different ways of reading the adc value (one with the built in adc command and one with messing with the registers directly). I have also tried different test boards (one is a homemade pcb etched with the toner transfer method and another was built on a standard breadboard).
The ADC's vref is set to vcc. I can get 0 whenever I set the AN0 pin to GND. I get around 1012 - 1013 when I set the AN0 pin to VCC (+5v). My vcc is a stable 5v dc (checked with two meters).
My current code for reading the adc is:
Code:
reading var word
avgloop var byte
avgtotal var word
CMCON = 7 ' Comparators OFF
ANSEL = %00100001 ' AN0 enabled (last 4 bits are enable bits {AN3:AN0}
ADCON0 = %10000001 ' VCC Vref / Turn On ADC Module
readadc:
' Take 20 readings and average them for accuracy
avgtotal = 0
for avgloop = 1 to 20
ADCON0.1 = 1 ' Start ADC
loopadc:
if ADCON0.1 = 1 then goto loopadc ' Check to make sure ADC conversion finished..
pause 5 ' Give ADC Settling Time
reading.highbyte = ADRESH
reading.lowbyte = ADRESL
avgtotal = avgtotal + reading
next avgloop
reading = avgtotal / 20
return
I am using a 12F675 with pbp 2.44.
Harrison
Bookmarks