loading

pic 16f690 ADC setup- solved

Hi, i'm trying to get the ADC module on the 16f690 operational.

The analog input is on A0, and is variable between 0V and about 1.8V.

The result is just displayed in the format it comes out of the converter on 8 LED's (all tested and functional) on C0 to C7.

When I run the code, it continuously displays '10001100xx'  (the two least significant bits are not displayed, so are unknown)

The .asm file attatched (will open in notepad) compiles ok, with no errors, and the warnings about the correct bank have been checked.

The configuration used is as follows:
INTOSCIO oscillator: I/O on A4, A5
WDT disabled
PWRT disabled
MCLR tied to VDD, I/O on MCLR pin
code protection disabled
BOR disabled
internal/external switchover mode disabled
fail safe clock monitor disabled

Thanks for any help.


I'm horrible when it comes to trying to debug others code, but I did notice the following lines in your code:

BSF ANSEL,0 ;A0 ANALOG
MOVLW B'00000001'
MOVWF ANSELH ;ADC ON, A0
CLRF CM1CON0 ;COMPARATORS OFF
CLRF CM2CON0 ;COMPARATORS OFF
BCF STATUS,RP1 ;PAGE0

I think that in the line which reads "MOVWF ANSELH ;ADC ON, A0:
you intend to turn the A/D on. But, the register that contains the ADON bit is ADCON0, not ANSELH. Prior to the code above you have a line that clears ADCON0, so the A/D would be off to begin with.

I hope I am interpreting this correctly. Good Luck!


The Skinnerz (author)  LargeMouthBass6 years ago
Wow, it actually works now.

As you pointed out, it was the wrong register to enable the ADC.

the CLRF ADCON0 is left over from the previous code to set everything working as digital I/O, and does not appear to affect functionality.

Thanks for the quick reply.