PDA

View Full Version : adcon1/ adcin



Patrick
- 7th July 2006, 13:25
Why is it that I can only read on portA 2,3
Program that I used suggested that I use portA,0
Want an easy explenation on the adcon1 bits and there relationship between adcon and adcin
please

Patrick





'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : P van Biljon *
'* Notice : Copyright (c) 2006 Ver:2.44 *
'* : All Rights Reserved *
'* Date : 2006/07/07 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
DEFINE LOADER_USED 1 ' If using bootloader to program pic
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portc connected to LCD DC4
DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 1 'Define Portc pin used for RS connection
DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortC pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.
define osc 4
define adc_bits 8
define adc_clock 1
define adc_sampleus 50


samples var word
sample var byte
temp var byte
samples = 0
samples1 var word
sample1 var byte
temp1 var byte
samples1 = 0


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = 2
pause 500


init:
samples = 0
samples1 = 0
gosub loop
gosub loop1
gosub loop2
goto init




loop:

for sample = 0 to 20
adcin 2 ,temp
samples= samples + temp
pause 100
next sample
temp = samples / 20

return

loop1:

for sample1 = 0 to 20
adcin 3 ,temp1
samples1= samples1 + temp1
pause 100
next sample1
temp1 = samples1 / 20

return
loop2:
lcdout $fe,1,"Temp is: " ,DEC(samples/10) ,".",dec2 samples," C"
lcdout $fe,$C0,"Temp is: " ,DEC(samples1/10) ,".",dec2 samples1," C"

goto init
end

BobK
- 7th July 2006, 15:37
Hi Patrick,

It would really help us if we knew which PIC you were using!

Some PIC's have comparators as well as analog inputs set up on the PortA pins that need to be disabled before the pins will work properly.

BobK

Patrick
- 8th July 2006, 07:44
Hi

I am using a 16F876
Read up last night on A/D
modified to:Stil does not work

DEFINE LOADER_USED 1 ' If using bootloader to program pic
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portc connected to LCD DC4
DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 1 'Define Portc pin used for RS connection
DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortC pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.
define osc 4
define adc_bits 8
define adc_clock 1
define adc_sampleus 50


samples var word
sample var byte
temp var byte
samples = 0
samples1 var word
sample1 var byte
temp1 var byte
samples1 = 0


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %01001001
pause 100


init:
samples = 0
samples1 = 0
gosub loop
gosub loop1
lcdout $fe,1,"Temp is: " ,DEC(samples/100) ,".",dec2 samples," C"
lcdout $fe,$C0,"Temp is: " ,DEC(samples1/100) ,".",dec2 samples1," C"

goto init


loop:
adcon0 = $41
pauseus 50
adcon0.2 = 1
pauseus 50
for sample = 0 to 20
adcin 0 ,temp
samples= samples + temp
pause 100
next sample
temp = samples / 20

return

loop1:
adcon0 = $49
pauseus 50
adcon0.2 = 1
pauseus 50
for sample1 = 0 to 20
adcin 1 ,temp1
samples1= samples1 + temp1
pause 100
next sample1
temp1 = samples1 / 20

return

end

Melanie
- 8th July 2006, 08:49
You went from something good like this...

ADCON1 = 2
.. ..
for sample = 0 to 20
adcin 2 ,temp
samples= samples + temp
pause 100
next sample
temp = samples / 20

...and all you had to do was change ADCIN 2 to ADCIN 0 (PBP Manual!) for it to read from RA0/AN0, to something like your second example which is completely shot.

For complete definitions of ADCON0 and ADCON1 see your PICs DATASHEET.

Patrick
- 9th July 2006, 07:39
Thanks Melanie

Out of desparation I looked at the sample on the Rentron page where they use the three pots on the inputs of the RA ports of the 16F87X pics,that is where the second example comes from.
If I program the pic as in example one I have 5volt on pin RA0 and 1 and I want to read from LM34 temp IC
If I make it Adcon1 = 2 and read on pin 2 and 3 it reads it but I want to know why I cannot get a reading from pin 0 and 1 when the IC is connected.I can also not figure it out on the data sheetsas Adcon1 = 2 makes the pins all analog with no Ref voltage on pins.

Please if someone can again simplify these settings ,I know that there is being many mails on this subject but,can someone point to a site or mail which makes it simple and just not repeat the data sheet.

Sometimes I just caun't see the obvious, but then I need help and that is why there is a great forum like this.

Melanie keep up the good work

Patrick van Biljon