View Single Post
  #2   Spotlight this post!  
Unread 09-01-2004, 22:31
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: ADC problems with C library and new code

It turns out there is a bug with SetChanADC() - you need to right shift the channel one bit. This is clearly a bug in the C library since the OpenADC() function works correctly with the standard channels.

So, do the ADCopen once in your init code, then you can write a lean:

unsigned int GetADC(unsigned char chan)
{
SetChanADC(chan>>1);
Delay10TCYx(5);
ConvertADC();
while(BusyADC());
return ReadADC();
}