Hey guys, got some problems with my PIC again.
I was trying to set up an AD converter for my pic16f877a and I've managed to with moderate success, but I've encountered a problem here: seems that the converter cannot keep up with the speed of the rest of the system and clogs it up. I've got almost the entire space in terms of pins used up, got an LCD screen, a rotary encoder and almost 2 dozen of other pins used as output, so might it have something to do with it? The rest of the system works at around 250Hz, but once I start up the reading of the analog inputs, it slows down to maybe 3-4 cycles per second. Here's the code for the reading of the encoder:
A pretty simple code, but there seems to be a problem somewhere in there, I'm guessing it takes too long to read the voltage? I've tried fiddling with different frequencies for the converter and even setting it to work only once every several (dozen) cycles, but to no avail. Did I push my PIC to its limits or is something else at play here?
Rich (BB code):
int readAD(char channel)
{
int value;
ADCON0 = 64 + (channel << 3) + 1;
DelayUs(2);
ADRESL = 0;
ADRESH = 0;
GO_DONE = 1;
while (GO_DONE);
value = ADRESL;
value += ADRESH * 256;
return value;
}