Hi,
It depends if you're using ADCIN or manually "driving" the ADC module.
* You need to set the appropriate pins to analog which on the 12F510 is done thru bits 6 and 7 of ADCON0.
* Bits 4 and 5 selects from where the ADC gets it clock. When using ADCIN you can DEFINE ADC_CLOCK 3 which basically sets those two bits to 11, selecting INTOSC/4.
* Bits 2 and 3 selects WHICH of the analog channels that actually gets connected to the ADC. There's only ONE converter, each channel is multiplexed to that single converter by selecting it thru these bits. If using ADCIN it handles these bits for you based on the channel number you specify in the command. Ie ADCIN 1, ADVal will set these bits to 01 selecting channel 1.
* After selecting a channel you should wait a certain amount of time for the capacitor in the sample and hold circuit to charge. When using ADCIN this time can be specified thru DEFINE ADC_SAMPLEUS
* Bit 1 is the "start button" for the conversion. You set it to start a conversion and the ADC clears it again when the conversion is complete and result is available. When using ADCIN it handles this for you.
* ADCON0.0 is the "mains switch" for the ADC module. It needs to be set in order for the ADC to work but simply setting it does NOT actually perform a conversion. The actual conversion is initiated thru bit 1.
Read the complete ADC section in the datasheet - don't just look at the register. It explains it pretty well and this ADC is basically as simple as they get in a PIC so it's a great start for learning. It does not, however, tell you what the PBP ADCIN command handles for you and what it doesn't but understanding how it works makes it a lot easier to debug when it doesn't work...
/Henrik.
PS. On the 12F510 the ADC is 8 bits so your DEFINE ADC_BITS 10 won't work properly.
Bookmarks