![]() |
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! |
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(); } |
| All times are GMT -5. The time now is 16:54. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi