|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
ADC problems with C library and new code
Has anyone successfuly manipulated the ADC hardware directly? It appears that the C compiler function "SetChanADC()" doesn't work correctly. I have tried to set the channel manually but can't seem to get it to work correctly.
The PIC (and IFI) defines show the channel # shifted left three bits, but the 18F8520 data sheet shows them shifted only 2 bits. SetChanADC() doesn't shift the bits at all. OpenADC() does the right thing with the channel, but I don't want the overhead... Cheers! |
|
#2
|
|||
|
|||
|
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(); } |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The New and Improved FIRST CAD Library | Ed Sparks | General Forum | 22 | 03-02-2007 18:03 |