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

Problem with conversion ADC in CCS

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



Joined: 08 Jun 2010
Posts: 13

View user's profile Send private message Yahoo Messenger

Problem with conversion ADC in CCS
PostPosted: Sat Jul 17, 2010 4:56 am     Reply with quote

Hello every one !
I made a real circuit with the following schematic:

I used USB voltage 5V.Temperature sensor:LM35
The circuit well worked,but the result not precise.
My code:
Code:
void main()
{


   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   lcd_init();
 
   setup_ADC(ADC_CLOCK_INTERNAL);
   setup_ADC_ports(AN0|VSS_VDD);//Vref=Vdd-Vss=5V
   set_ADC_channel(0);
   delay_us(10);
   while(1)
   {
      adc=read_ADC();
      adc=adc*500/1024;//i fused Vref=5V,#device adc=10
      LCD_putc("Temperature:         ");
      LCD_putc("\n");
      LCD_putc("T=");
      printf(lcd_putc,"%f",adc);
      LCD_putc("*C");
      delay_ms(100);lcd_gotoxy(1,1);
   
    }
     
  }

But the above code I simulated on Proteus precisely worked.
I really don't understand what happened.
I have debugged so much, I think my code did not mistake, and every thing perhaps very logic. But...
Please help me!!!
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 17, 2010 5:57 am     Reply with quote

Welcome to the REAL world where simulations always fail !

I've used the LM35 for almost 3 decades..

In ANY analog circuit there will be noise, so..
add 100mfd// .01 disk caps on the VCC of the LM35.
add 10 mfd cap on the output pin as well.

Depending on distance of LM35 to PIC, it'll pickup noise. You can add an opamp voltage buffer to minimize this effect. I do this for runs up to 100' all the time.

On the PIC side...
take several readings and then average the result

this should help get you stable in the real world.
Jay
SherpaDoug



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

View user's profile Send private message

PostPosted: Sat Jul 17, 2010 6:49 am     Reply with quote

If the readings are mostly correct with occasional bad ones, search for "olympic average" for a very simple routine that kills bad data points to get the correct average with very little processing.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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