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 support@ccsinfo.com

PIC 18F67J50, CCS 4.104, Strange problem with A/D converter

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



Joined: 16 Apr 2009
Posts: 18
Location: Spain

View user's profile Send private message

PIC 18F67J50, CCS 4.104, Strange problem with A/D converter
PostPosted: Fri Jan 28, 2011 3:24 am     Reply with quote

Hello everybody,


I'm using a PIC18F67J50 to measure temperature using thermistors.

First of all I calibrate the AD (a functionality of this PIC AD converter...)

My AD converter configuration is this:

Avdd -> 3.3V (general system power...)
Avss -> GND
Vref+ -> 3.0V (from a voltage reference...)


I read 4 thermistor (using some AmpOp...) using as references 3.0V and GND.
I read the BAT level using as references VDD and GND.

When working, the device allways do the same, each minute, it reads all channels, store the readings in EEPROM and transmits them, no more. But suddenly, after some hours of work, something goes wrong and three channels (battery included) don't work.

Battery readings become 0V. But when this error occurs, if I test the PCB I find it ok. Power is OK and voltage reference too. If I measure the battery input pin I see a correct Voltage...

¿Have everybody experienced some problem like this whith the AD converter??

This is a sample of my AD configuration:

Code:

   //In the first time, all values to 0, in order to acces ADCON0, ADCON1 I must switch the bit ADSHR in WDTCON register....
   WDTCON_ADSHR = 0;     
   ADCON0 = 0;
   ADCON1 = 0;
   WDTCON_ADSHR = 1;     
     ANCON0 = 0;         
     ANCON1 = 0;
   
   //------------------
   //  channel config
   //------------------
   WDTCON_ADSHR = 0;         //normal access...
      ADCON0_ADON = 0;         //ADC off 
      ADCON1_ADFM = 1;         //left justified...
      ADCON1_ADCAL = 0;        //normal conversion (not calibration...)
   WDTCON_ADSHR = 1;       //Acceso registros compartidos...
      ANCON0 = 159;            //Channels AN0, AN1, AN2, AN3(Vref+), AN4, AN7, AN10 y AN11 configured as analogs
      ANCON1 = 12;
   WDTCON_ADSHR = 0;      //normal access...
      ADCON0_VCFG1 = 0;        //VSS
      ADCON0_VCFG0 = cREF;     //VDD o VRef+  (it depends on the channel...)   
   
      //channel selection:
      ADCON0 &= CH_MASK;   //I erase only the channel bits
      ADCON0 |= cCHAN_SELECTED;     //Now I set the appropiate channel...
   
   delay_us(50);
   
      ADCON1_ACQT2=0;
      ADCON1_ACQT1=0;    //Adquisition time --> 0Tad
      ADCON1_ACQT0=0;
      ADCON1_ADCS2=0;
      ADCON1_ADCS1=0;   
      ADCON1_ADCS0=1;
   
      ADCON0_ADON = 1;   //ADC ON

    delay_us(50);

    //and now I start the conversion:
    fMeasure = (float)read_adc(ADC_START_AND_READ);


I repeat this configuration for each channel changing the references and selected channel.


Thanks you in advance....
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

Re: PIC 18F67J50, CCS 4.104, Strange problem with A/D conver
PostPosted: Fri Jan 28, 2011 7:56 am     Reply with quote

rvalor wrote:
When working, the device allways do the same, each minute, it reads all channels, store the readings in EEPROM and transmits them, no more. But suddenly, after some hours of work, something goes wrong and three channels (battery included) don't work.


Are you storing these values in the PIC's internal EEPROM? If so, that could be part of the problem, as you've likely worn it out.
rvalor



Joined: 16 Apr 2009
Posts: 18
Location: Spain

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 8:03 am     Reply with quote

Hello newguy.

I'm not storing data in the internal PIC memory. I use a 24LC512 external memory.
When data must be stored I disable all the interrupts in order to avoid problems in the timing of the I2C communication.

Do you think it could be a problem related with the impedance of the circuits connected to the analog to digital channels?

In the other hand I'm monitoring some variables in order to prevent they become corrupted...

I'm a bit confused, the device works fine for a lot of hours and the problem appears suddenly.

Thanks you.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 1:05 pm     Reply with quote

The 24LC512 datasheet says it is good for 1 million cycles. At 1 cycle per minute that is about 2 years. That is enough for a home project, but kind of limiting if this is a product to be sold.

Can you store the last few readings in RAM and check them when you detect a failure? Or maybe when you find a failure read a few more times and store them in a new section of EEPROM to be dumped for diagnosis.

Another thought... Are you using a large ring buffer that maybe does not wrap properly when it fills up? What is the buffer memory address where things start to go bad?
_________________
The search for better is endless. Instead simply find very good and get the job done.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 1:26 pm     Reply with quote

Any chance the device that receives the data is 'going to sleep' or otherwise failing?
If I assume you're transmitting to a PC, is it a minimal system. No antivirus s/w, no Internet connection, etc. Just a simple terminal program running.
Hmm..using real RS232 or a USB<>RS232 adapter ?
USB has a lot of problems compared to 'legacy' comports.

Perhaps you can add a 'reading counter' to go with the data. See if it always fails at nnnnn counts, or is random. If you could attach an LCD to the PIC to display the count and data...
..even an LED that toggles every transmission would help.
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