PDA

View Full Version : PIC16F818 ADC Problem



BobEdge
- 18th July 2006, 09:48
Hi,

I am using a pic16f818, and am having trouble with the a/d convertor. I just have a pot & an LED, here is the program:

define OSC 8
define adc_bits 10
define adc_sampleus 50
TRISA = 255
ADCON0 = 193
ADCON1 = 128

led var portb.1
value var word

start:
adcin 0, value
if value = 0 then value = 1
high led
pause value
low led
pause value
goto start
end

When I turn the pot I get a delay of 1, 2, or 3 mS. I would expect a delay of upto 1023mS. Can anyone please help?

peterdeco1
- 18th July 2006, 10:30
Hi Bob. This is how I use the 818 & 819. I prefer the easier 255 step ADC but used the 1024 in the past with no problem.

OSCCON = $60 'set int osc to 4mhz
'USE OSCCON = $70 for 8mhz
adcon1 = 7 ' set inputs to digital. adcin command will convert to analog
MYVAR VAR BYTE

'uncomment & use the following 4 lines for 1024 step conversion INSTEAD of 'var byte
'MYVAR VAR WORD
'DEFINE ADC_BITS 10 ' Set number of bits in result
'DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
'ADCON1.7 = 1 'RIGHT JUSTIFY RESULT

@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON

BobEdge
- 18th July 2006, 11:41
Thanks, but I just tried that & still get the same results, a maximum of 3 as the a/d result. I have tried chips from different batches, various settings for the adc clock, I am using a 8MHz resonator for the clock. I have measured the voltage on the pin (pin 17), and it varies from 0 to 5V. I have used the 818 in the past with no problems. That time I had a 20MHz osc, so I used clock / 64, i.e. ADCON0 = 129, ADCON1 = 206 and it worked fine. I just cant see why it wont work.

Oh well I'll keep trying....

peterdeco1
- 18th July 2006, 14:19
Try not using your ADCON statements. I've never used them & always worked for me. Also try the internal oscillator @ 4MHZ. Your program looks like it should work.

BobEdge
- 18th July 2006, 14:56
Thanks for your help.

I have got rid of the ADCON commands, and fitted an lcd display, it now works, kind of. It will work as an 8 bit a/d. Very strange, as I said I have used the 10 bit a/d of an 818 before. 8 bits will do though, in this case.

Regards
Bob...