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

Multiple Conversion problem

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



Joined: 12 Dec 2010
Posts: 6
Location: Turkey

View user's profile Send private message AIM Address

Multiple Conversion problem
PostPosted: Tue Mar 29, 2011 7:18 pm     Reply with quote

hi everyone.
It's short question. I'm using 16f877 and I'm using 3 adc inputs.
Inputs:
1. input = keypad
2. input = Temperature (using lm35)
3. input = measurement weight

The problem is:
Keypad working well.
Temperature is so flexible. For example, I can read 19'C and 25'C in a few seconds.
3. Input is changing when Temperature change.
What would be the problem?
Code:

void main()
{
// tüm kanallar kullanılacak.
//setup_adc_ports( ALL_ANALOG );
set_tris_a(0xff);
set_tris_d(0x00);
setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
setup_adc(ADC_CLOCK_DIV_32);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);;

glcd_init(on);
glcd_fillScreen(on);
glcd_line(0, 0, 128, 0, off) ;
glcd_line(127, 0, 127, 63, off) ;
glcd_line(127, 63, 0, 63, off);
glcd_line(0, 63, 0, 0, off);
glcd_text57(3,5, Welcome, 2, Off);
glcd_text57(3,25, Welcome1,2, Off);

delay_ms(500);

set_adc_channel(3);

g1=read_adc();
delay_us(100);
g2=read_adc();
delay_us(100);
g3=read_adc();
delay_us(100);
g4=read_adc();
delay_us(100);
g5=read_adc();
gs=((g1+g2+g3+g4+g5)/5);

while(1){ agirlik_oku()
{
//measurement weight
   set_adc_channel( 3 ); 
   delay_ms(100);
   g1=read_adc();
   delay_ms(50);
   g2=read_adc();
   delay_ms(50);
   g3=read_adc();
   delay_ms(50);
   g4=read_adc();
   delay_ms(50);
   g5=read_adc();
   delay_ms(50);
   i=((g1+g2+g3+g4+g5)/5);
  //  a=(i-gs);
   agirlik=(a*0.01953125)/2;

   return agirlik;
}

tus_oku(){
// reading keypad
do{
set_adc_channel( 0 );
delay_us(100);
key = read_adc();
if(key>=800 && key<=810){tus=7;}
if(key<=673 && key>=662){tus=8;}
if(key<=510 && key>=505){tus=9;}
if(key<=799 && key>=790){tus=4;}
if(key<=661 && key>=655){tus=5;}
if(key<=504 && key>=500){tus=6;}
if(key<=780 && key>=770){tus=1;}
if(key<=652 && key>=645){tus=2;}
if(key<=499 && key>=493){tus=3;}
if(key<=740 && key>=750){tus=20;}
if(key<=630 && key>=620){tus=0;}
if(key<=487 && key>=483){tus=21;}
}
while(key<=0x60  && key>=0x00);
return tus;
}

sicaklik_oku(){
set_adc_channel(1);
delay_ms(100);
bilgi=read_adc(); 

voltaj=(0.0048828125*bilgi)*1000; 
sicaklik=(voltaj/10)+2;   
// measurement temperature
}
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Mar 29, 2011 9:02 pm     Reply with quote

See if your LM35 is oscillating. It may need some bypass caps. Look at the LM35 datasheet for recommendations.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Mar 30, 2011 2:10 am     Reply with quote

As another little comment, change the line:

setup_spi(SPI_SS_DISABLED);

either to:

setup_spi(FALSE);

or just remove the line!...

This is a fault with the CCS wizard, and the option SPI_SS_DISABLED, turn off 'slave select', but turns _on_ the SPI. The SPI is disabled by default, or 'FALSE', does disable it, but having it 'on', can lead to unexpected things happening.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 30, 2011 5:53 am     Reply with quote

Not shown but...I assume..
you setup the ADC for 10 bit mode ?
and defined the ADC variables as floats( globally )?

I use a .68/15 cap on my LM34 projects, if close to the PIC. For distance(200' or less) I buffer using an LM358 voltage follower and triple-PI filter.

Sampling is done with delay_us(20) between readings.
chalukg



Joined: 12 Dec 2010
Posts: 6
Location: Turkey

View user's profile Send private message AIM Address

PostPosted: Wed Mar 30, 2011 9:57 am     Reply with quote

temtronic wrote:
Not shown but...I assume..
you setup the ADC for 10 bit mode ?
and defined the ADC variables as floats( globally )?

I use a .68/15 cap on my LM34 projects,if close to the PIC. For distance(200' or less) I buffer using an LM358 voltage follower and triple-PI filter.

Sampling is done with delay_us(20) between readings.

thats right but in this code i used
Code:
set_adc_channel(1);
delay_ms(100);
bilgi=read_adc(); 
voltaj=(0.0048828125*bilgi)*1000;   
sicaklik=(voltaj/10)+2;
return sicaklik;
temtronic



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

View user's profile Send private message

PostPosted: Thu Mar 31, 2011 2:16 pm     Reply with quote

hmm..
Instead of the LM35, use a pair of fixed resistors for a test.See if the reading is constant(+- 2 or 3 bits).If so the problem is probably the LM35 circuit ,needs filtering.
If the test isn't stable, then Vref may be bad,especially if it's really VDD.Again more filtering may be needed,power supply decoupling caps, etc.

Also I see in one line you ...*1000
next line .../10

Unless you use the intermediate value elsewhere, just ....*100
It should save you some time and be more accurate.
chalukg



Joined: 12 Dec 2010
Posts: 6
Location: Turkey

View user's profile Send private message AIM Address

PostPosted: Sat Apr 02, 2011 9:42 am     Reply with quote

temtronic wrote:
hmm..
Instead of the LM35, use a pair of fixed resistors for a test.See if the reading is constant(+- 2 or 3 bits).If so the problem is probably the LM35 circuit ,needs filtering.
If the test isn't stable, then Vref may be bad,especially if it's really VDD.Again more filtering may be needed,power supply decoupling caps, etc.

Also I see in one line you ...*1000
next line .../10

Unless you use the intermediate value elsewhere, just ....*100
It should save you some time and be more accurate.

allright i found it. the problem is lm35. but another problem hasnt been solved. i still can not read another adc ports.
temtronic



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

View user's profile Send private message

PostPosted: Sat Apr 02, 2011 6:19 pm     Reply with quote

You'll need to show us a small program that won't read the other ADC channels.
The original one only accesses channel #3.
chalukg



Joined: 12 Dec 2010
Posts: 6
Location: Turkey

View user's profile Send private message AIM Address

PostPosted: Tue Apr 05, 2011 2:15 am     Reply with quote

one of my friend said that close the adc then change the channel and re open adc. and it s work
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