PDA

View Full Version : 16F1827 ADC Direct manipulation not working



Ioannis
- 5th June 2013, 15:06
While using ADCin works fine, using direct register manipulation does not. Can anyone tell me why?



PORTA = 0
PORTB = 0
TRISA = %00000011
TRISB = %00001011

ADCON0 = %00000000 'select channel AN0, ADC off
ADCON1 = %01110000 'Internal Frc, Left justified, Ext. ref.

ANSELA = %00000001 ' AN0 on Port A analog
ANSELB = %00000000 ' Digital inputs

start:
adcon0.1=1
while adcon0.1:wend
hserout ["Adresh: ",#adresh,13,10]
pause 1000
goto start


The above does not work. The next one works just fine though...



start:
pause 1000
adcin 0,i
hserout ["Adc: ",#i,13,10]
goto start


Thanks,
Ioannis

mark_s
- 5th June 2013, 16:36
Hi Ioannis,

I think your while loop needs to be

ADCON0.1=1
WHILE ADCON0.1=1
wend

Darrel Taylor
- 5th June 2013, 18:19
while adcon0.1 and while adcon0.1=1 are functionally identical.

However, the A/D module must be turned on before it will perform a conversion.

ADCON0.0 = 1

PBP does that automatically.

Ioannis
- 5th June 2013, 21:42
Hi Darrel.

Thanks for looking at this. Well, I do have this line, just did not copy it when posting the thread.

The strange thing is that, if I use both ways, ADCin and register manipulation, it works!

Like this works fine:



high adcon0.0'=1

start:
adcon0.1=1
while adcon0.1:wend
hserout ["Adresh: ",#adresh,13,10]
pause 1000

adcin 0,i
hserout ["i: ",#i,13,10]
goto start


But not when modified to this:



high adcon0.0'=1

start:
adcon0.1=1
while adcon0.1:wend
hserout ["Adresh: ",#adresh,13,10]
pause 1000

'adcin 0,i
'hserout ["i: ",#i,13,10]
goto start


Cannot figure out why...
Ioannis

Ioannis
- 5th June 2013, 21:55
OK, I found something but cannot tell if it is a bug or something I don't understand.

Setting up the ADCON0 as

ADCON0.0=1
PAUSEUS 100
ADCON0.1=1

does not work.

But ADCON0=3 does work just fine!

Ioannis

Ioannis
- 5th June 2013, 22:16
Ooops,no bug!

I got it.

Wrong label...

Sorry for the alarm.

All are OK.
:o
Ioannis