PDA

View Full Version : adcin trouble



PickyBiker
- 29th March 2010, 21:54
I am experimenting with a servo tester to gain some experience with pic programming. Especially reading a pot, and a switch to control the servo output. The pic is a 16f683 and I can get it working and I can read the switch, but I have so far failed to get anything but 0 from the pot.

The pot input is pin 6, AN1 and I have verified that it varies the voltage from 0 to +5.

Here is the relavent portion of code:
--------------------------------------------------------------------------
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC SAMPLES 50

TRISIO = %11111110 ' set porta.0 output and all other to inputs
ANSEL = %00000010 ' porta.1 to analog, others to digital
ADCON0 = %10001001 ' analog input on porta.1, Right justify result
CMCON0 = %00000111 ' Turn of the comparators
PORTA = %00000000 ' set porta to all 0's

pulse_width var word

adcin porta.1, pulse_width
--------------------------------------------------------------------------
Any help would be appreciated.
Thanks,

Mike

mackrackit
- 29th March 2010, 22:31
I will assume you mean 12F683 ?

There is not a PORTA.


TRISIO = %11111110 ' set GPIO.0 output and all other to inputs
ANSEL = %00000010 ' porta.1 to analog, others to digital
ADCON0 = %00000100 ' analog input on GPIO.1, Left justify result for 8 bit
CMCON0 = %00000111 ' Turn of the comparators
GPIO = %00000000 ' set porta to all 0's

adcin 1, pulse_width


Give it a try.. No guarantees...

PickyBiker
- 29th March 2010, 23:55
Thanks MACKRACKIT.

You were right on both counts.

Next is timer control and then interrupts.

Thanks for the help.