Ttelmah
Joined: 11 Mar 2010 Posts: 19500
|
|
Posted: Wed Oct 27, 2010 1:51 pm |
|
|
Internally the ADC value is read from a capacitor.
The input inside the chip, and the multiplexer in particular have resistance.
The capacitor takes _time_ to charge.
This is in the PIC data sheet. ADC section.
You need to select the channel, then _wait_ for the capacitor to charge. Then take the reading. The wait duration will depend on the PIC involved, read the data sheet.
Your 'start only' ADC lines are pointless. These are only wanted when you use the 'read only ' option once the chip has performed the conversion.
So the sequence needs to be:
1) select channel
2) wait for the acquisition time.
3) read the adc.
Also check whether ADC_CLOCK_INTERNAL is legal for your clock rate?. Normally not if you are operating above 1MHz, unless you put the PIC to sleep for the conversion.
To do this, you need to enable the ADC interrupt, disable global interrupts, and all other interrupts, set read_adc(ADC_START_ONLY), then immediately put the chip to sleep. When it wakes, use ADC_READ_ONLY to get the value and set the interrupts back to normal.
Best Wishes |
|