CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18LF2420 ADC Problem - SOLVED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

18LF2420 ADC Problem - SOLVED
PostPosted: Wed May 23, 2012 10:50 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2012 11:38 pm     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu May 24, 2012 1:52 am     Reply with quote

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
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu May 24, 2012 2:25 am     Reply with quote

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
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Thu May 24, 2012 9:30 am     Reply with quote

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
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Thu May 24, 2012 10:03 am     Reply with quote

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
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Thu May 24, 2012 10:16 am     Reply with quote

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
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

18LF2420 ADC Problem - SOLVED
PostPosted: Thu Jun 07, 2012 12:12 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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