|
|
View previous topic :: View next topic |
Author |
Message |
commlinx2 Guest
|
Weird 18F67J10 ADC problem |
Posted: Wed Jun 21, 2006 3:59 am |
|
|
Hi All,
I have an odd problem with a PIC18F67J10 application I'm working on. It's running a little below 40MHz with PLL on and despite trying a variety of different methods of reading the ADC I get a mix of spot-on readings mixed with a reading of 512 about 20% of the time which obviously corresponds to half the FSR.
The simplest analog input is a battery voltage monitor with a 10K/2K7 divider to an analog pin so I thought I'd use that for isolating the problem. I removed code that switches to other analog channels in case of channel switching settling time issues and am using the following ADC init code:
Code: | setup_adc_ports(AN0_TO_AN4|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
ADCAL = 1;
read_adc();
ADCAL = 0;
|
It's the first time I'd used a device with the ADCAL bit, so I also tried with the last 3 lines removed and have tried ADC_CLOCK_DIV_32 as the datasheet suggested this would be OK at 40MHz. None of these changes made any difference. In addition to the usual read_adc() call I tried the following code which yielded the same result:
Code: | float get_battery_voltage()
{
set_adc_channel(VBATT);
delay_ms(1);
read_adc(ADC_START_ONLY);
delay_ms(1);
return read_adc(ADC_READ_ONLY);
}
|
Obviously the full code has a conversion factor for volts, but after removing it I discovered the amount of 512 readings which seems like an unusual value to get for a unipolar ADC. Any ideas on why this would be happening?
It is a properly laid out SMT PCB based on a similar design with a PIC18F8720 that works well, so apart from that the consistent perfect versus 512 readings leads me to believe there is something odd going on. Also when I say 'perfect' readings they are what I expect within a few readings difference, as expected there will be some small error and difference in supply voltage.
Regards,
Peter. |
|
|
commlinx2 Guest
|
Weird 18F67J10 ADC problem |
Posted: Wed Jun 21, 2006 4:08 am |
|
|
OK, I should have read the errata as well as the datasheet . For anyone that has the same problem look at the errata sheet on the Microchip site for info on the workaround for when the ADC clock is divide by 16, 32 or 64. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|