![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ajt
Joined: 07 Sep 2003 Posts: 110
|
18LF2420 ADC Problem - SOLVED |
Posted: Wed May 23, 2012 10:50 pm |
|
|
Using the ADC as a 3.7V Li-Ion battery monitor. ADC Input is thru a divider of 2 x 2K 1% resistors and 100nF filter cap. Vref is 3.0V LDO and PIC is powered from a 3.3V LDO. Compiler is 4.132. Oscillator is 20MHz crystal.
Every so often (can't figure out a pattern) the ADC output gets into a state where it is reporting high by about 10%. Restarting doesn't fix it. I have tried everything I can think of in hardware and firmware to fix this but cannot. All voltages are clean and except for the ADC input are the right value. No interrupts are involved. I have also checked the errata on the PIC18LF.
The DC voltage on the divider when in this state is higher than it should be and the ADC is reporting accordingly. I can't see why the voltage is higher unless the PIC is sourcing current. An example is a battery voltage of 4.08V, divider reading 2.24V (instead of 2.04V) and ADC is reporting 2.33V (0x031A).
There is a 2.4GHz radio module on the board but it is operating the same when the ADC is working correctly and not.
Relevant code:
Code: | #device adc=10
#FUSES NOWDT, WDT128, HS, NOFCMEN, NOIESO, NOBROWNOUT, NOPBADEN, NOSTVREN, NOLVP, NOXINST
#use delay(clock=20000000)
....
setup_adc_ports(AN0, VSS_VREF);
setup_adc(ADC_CLOCK_DIV_32);
....
int16 vBattery;
set_adc_channel(0);
delay_us(25);
vBattery = read_adc();
|
Any ideas on what is going on here? _________________ Al Testani
Last edited by ajt on Thu Jun 07, 2012 3:45 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 23, 2012 11:38 pm |
|
|
You need to post a schematic of the external circuit connected to pin AN0
and also a compilable test program that only tests that one problem. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu May 24, 2012 1:52 am |
|
|
Hi Al,
How are things?. Perhaps chat 'off board'?.
An oddity. I'd be suspicious of a signal on another pin somewhere, getting injected through the FET's forming the ADC multiplexer, or possibly some very short spike causing a latch-up, possibly on the one from Vref. Does it do the same without the filter cap?. If not, then this is integrating something, and it comes down to working out 'what'. Realistically, the data that "Restarting doesn't fix it", says it has to be something like a latch up problem, which probably involves some tiny spike somewhere....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu May 24, 2012 2:25 am |
|
|
In that vein, check that all voltages applied to the analogue inputs, whether you use them of not, are in range: i.e. between Vref- and Vref+, and certainly between Avss and Avdd. Look out for voltages below 0V. The analogue inputs are especially sensitive to anything below ground and ALL the ADC readings are affected, even if its on an "unused" input.
RF Developer |
|
![](templates/subSilver/images/spacer.gif) |
ajt
Joined: 07 Sep 2003 Posts: 110
|
|
Posted: Thu May 24, 2012 9:30 am |
|
|
Ttelmah wrote: | Does it do the same without the filter cap?. If not, then this is integrating something, and it comes down to working out 'what'. Realistically, the data that "Restarting doesn't fix it", says it has to be something like a latch up problem, which probably involves some tiny spike somewhere....
|
Yes it does it with and without the filter cap and with various input resistor divider values. I am going back to look very carefully for spikes, etc. Unfortunately, I have "lost the problem" now and it is working as it should. I can't get it to fail again. _________________ Al Testani |
|
![](templates/subSilver/images/spacer.gif) |
ajt
Joined: 07 Sep 2003 Posts: 110
|
|
Posted: Thu May 24, 2012 10:03 am |
|
|
RF_Developer wrote: | In that vein, check that all voltages applied to the analogue inputs, whether you use them of not, are in range: i.e. between Vref- and Vref+, and certainly between Avss and Avdd. Look out for voltages below 0V. The analogue inputs are especially sensitive to anything below ground and ALL the ADC readings are affected, even if its on an "unused" input.
RF Developer |
Every pin on the 18LF2420 is in use. I am going to go back and look for spikes, etc. I can't right now as I have "lost the problem". I don't know what is causing this nor do I know how to make it happen. I did try it without any RF running (unplugged the radios) and still had the problem. In that case there were some open inputs.
I don't know what you mean by Avss and Avdd as the 18LF2420 only as one Vdd pin and two Vss pins. The Vdd pin has a 10uF ceramic immediately next to it. In terms of VRef+ and VRef-, I am using the ADC with a 3.0V LDO connected to RA3/AN3/REF+ and am using Vss as the REF- (i.e. setup_adc_ports(AN0, VSS_VREF); ). The LDO (LP2981) has a 100nF cap on the input and a 10uF ceramic on the output. I've checked that before for noise/spikes but will do it again if/when the problem reoccurs.
Specifically for the AN0 input close to the... a 10uF ceramic on the battery voltage, at the moment, two 4.02K 1% resistors in a divider and a 100nF on the resistor to ground. (I had tried all sorts of values for the divider including 2 x 2K and still had the problem... sometimes!).
This is clearly a board specific problem since I built up a board with only the necessary circuitry and wrote a standalone test program. That board worked fine (or I never ran into the problem with it) and the test code on the real board showed the problem.
I am beginning to think something is oscillating and probing or otherwise looking for it stops the oscillation. _________________ Al Testani |
|
![](templates/subSilver/images/spacer.gif) |
ajt
Joined: 07 Sep 2003 Posts: 110
|
|
Posted: Thu May 24, 2012 10:16 am |
|
|
PCM programmer wrote: | You need to post a schematic of the external circuit connected to pin AN0
and also a compilable test program that only tests that one problem. |
Here is the test program I was using to test this. It was compiled with v4.132:
Code: | #include <18LF2420.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH)
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, errors)
void main()
{
int16 adc_value;
float volts;
setup_adc_ports(AN0, VSS_VREF);
// setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
// setup_comparator(NC_NC_NC_NC);
// setup_adc(ADC_CLOCK_INTERNAL);
setup_adc(ADC_CLOCK_DIV_32);
while(TRUE)
{
set_adc_channel(0);
delay_us(10);
adc_value = read_adc();
volts = (float)(adc_value*2.0*3.0)/0x3FF;
printf( "%3.2f\r\n", volts);
// set_adc_channel(1); // just for test purposes
delay_ms(10);
}
}
|
This code runs fine on a separate board I built with only the relevant circuitry and fails (sometimes) on the board of interest. I am quite sure this is some strange hardware issue. The details of the circuitry are in other replies. _________________ Al Testani |
|
![](templates/subSilver/images/spacer.gif) |
ajt
Joined: 07 Sep 2003 Posts: 110
|
18LF2420 ADC Problem - SOLVED |
Posted: Thu Jun 07, 2012 12:12 pm |
|
|
The root cause of this problem was not related to the analog inputs but rather some other digital inputs. Some pins were coming from a 74HC14 that was powered directly from the raw battery voltage not the 3.3V regulated Vdd of the 18LF2420.
The problem seemed hard to replicate until I finally determined that it was only when a freshly charged battery was used. Li-ion batteries get charged to about 4.2V but the discharge curve is steep initially and the battery quickly settles into its nominal cell voltage of 3.6V
My mistake was checking that pin input voltage limits were in spec at the nominal cell voltage and overlooking the higher initial voltage of a fully charged battery. For the short time the battery was at its initial charge voltage some digital inputs over the voltage limit and this caused strange issues like the ADC input was actually sourcing current.
Connecting the offending 74HC14 to the PIC Vdd fixed the problem. _________________ Al Testani |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|