PDA

View Full Version : 18F1220 A/D Converter question



BobEdge
- 27th July 2011, 16:10
Hi,

I am a little confused about using the A/D converter.

I have a 10MHz resonator with PLL enabled.

This is how I have configured the A/D.

TRISA = 255
TRISB = %00000111
ADCON0 = %00000001 'Vref = Vss Vdd, turn on A/D
ADCON1 = %11111110 'Only Channel 0 analog
ADCON2 = %10110110 'Right justified, 16 TAD, TOSC/64 (for 40MHz)

This is how I am taking a reading.

atod:
ADCON0.1 = 1 'Start A/D conversion
while ADCON0.1 = 1 'Wait for it to finish
wend
adresult.highbyte = ADRESH
adresult.lowbyte = ADRESL
angletime = adresult * multiplier
temp = (adresult * decimal1) / 10
angletime = angletime + temp
temp = (adresult * decimal2) / 100
angletime = angletime + temp ' We now have phase angle delay
return

The results are a little jittery, even though the signal looks stable on the scope.
In the data sheet there is talk of taking readings in sleep mode, but I am not sure if this is just for the RC clock source. If I do need to be in sleep mode then the clock will be off, so do I need to set FOSC, and tad differently?

Best regards
Bob.

mackrackit
- 28th July 2011, 04:34
Not sure about the sleep mode, but do you have a capacitor between the ADC pin and VDD?

BobEdge
- 28th July 2011, 09:06
Hi,

Yes I do have a 1uF cap on the input, but between input, and Vss. Reading the data sheet a few times it is only necessary to sleep if using the RC osc.

The problem must be due to interference. My prototype boards do have quite a few wires all over the place, no ground plane, and when the welder is running at 2000A there must be large magnetic fields all over the place.

Strange though, even when idle the signal will be rock solid for 30 seconds or so, then it jumps all over the place for a bit, then solid again. No signs of anything on the input when using the scope in glitch detect mode. I suspect it would work fine on a propper pcb, with ground planes.

Regards
Bob.