-
ADCIN setup help need
Here's the problem I have.
I have used ADCIN using port a.0/ AN0 many times on many different projects with no problems, but I recently tried using a different port on the MCU for the ADCIN channel with no results. I'm using a 16f690 chip and portc.1/AN5. Can someone please help me with the proper setup for the ansel, adcon and adcon1 registers, as well as any setup for the TRISC settings to get the AD to work using the above channel or any other other channel besides the an0 channel. I usually don't have these problems, but this is driving me crazy. By the way, I'm also using a 5k pot connected to the portc.1 pin which reads 0-5v with my meter , so I know the electrical is good. I know I have to be doing something stupid in the setup.
Thanks for the help,
Dan
-
Post the code you are using that works for the channel you normally use and then we can show you what needs changed.
-
Hi, I have just browsed through the datasheet, and if I were doing it, I would set the following registers:
INTCON.7 = 0 'Disable interrupts
TRISC.1 = 1 'Set PORTC.1 to be an input
CM1CON0.7 = 0 'Disable Comparator module
CM2CON0.7 = 0 'Disable Comparator module
VRCON = 0 'Disable Voltage Reference module
ADCON0.7 = 0 'Right justify result. Assumes 10 bit AD conversion
ADCON0.0 = 1 'Enable ADC module
ANSEL.5 = 1 'Set high impedance buffer on ANS5 (PORTC.1)
Andy
-
ADCIN problem fixed
Thanks Andy,
While I was waiting for someone to reply, I broused the site and found what I was doing wrong. I always use all the stuff you said, but when I was using the ADCIN command, I was trying to read the port# not the AD channel number. Once I changed from the port# over to the channel number, everything worked perfectly. By the way, can anyone tell me why the ADCIN was working using the portA.0 address and not the channel # all the other times I used ADCIN. Just curious...PortA.0 is the only port that works this way. No other port does it. I can't find out why anywhere.
Thanks,
Dan
-
Hi Dan,
It may have been because PORTA.0 was currently at logic low, or as far as PBP is concerned, 0.
Effectively, you were writing:
ADCIN 0, Var
Which would have read from PORTA.0 anyway...
You could do the same to PORTA.1 if you pulled it high.
Andy