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

Reading 3 simultaneous entries AD

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



Joined: 03 Sep 2007
Posts: 7

View user's profile Send private message

Reading 3 simultaneous entries AD
PostPosted: Fri Nov 09, 2007 5:41 am     Reply with quote

Hello!

I am having trouble reading three simultaneous entries AD in my PIC16F877A.

The entries come into conflict and the values divide among themselves.

Please, somebody can help-me?

My Source code:

Code:

setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(0);
value_1 = read_adc();
setup_adc( ADC_OFF );


setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(1);
value_2 = read_adc();
setup_adc( ADC_OFF );


setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(2);
value_3 = read_adc();
setup_adc( ADC_OFF );
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Nov 09, 2007 6:21 am     Reply with quote

I think you should add a delay after the set_adc_channel() statement.
A delay_us(25) should be enough.

Hope this helps
b101101011011011



Joined: 03 Sep 2007
Posts: 7

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 7:20 am     Reply with quote

Thanks very much!

I put delay_ms(25), and worked!

Code:

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);

      while (true)   {

set_adc_channel(0);
delay_ms(25);
valor0 = read_adc();

      val320 = valor0 * 4 + ((int32)valor0 * 113)/128;
      p0 = ((int32)valor0 * 100) / 1024;

set_adc_channel(1);
delay_ms(25);
valor1 = read_adc();

      val321 = valor1 * 4 + ((int32)valor1 * 113)/128;
      p1 = ((int32)valor1 * 100) / 1024;

set_adc_channel(2);
delay_ms(25);
valor2 = read_adc();

      val322 = valor2 * 4 + ((int32)valor2 * 113)/128;
      p2 = ((int32)valor2 * 100) / 1024;
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Nov 09, 2007 7:50 am     Reply with quote

great.

But delay_ms(25) is a long time. as I said, delay_us(25) works perfectly for me so maybe you could try that to speed up your program ;)

Greetings
Ttelmah
Guest







PostPosted: Fri Nov 09, 2007 8:57 am     Reply with quote

Yes.
This is a 'read the data sheet' question/answer...
The ADC internally, is 'seen' as a small capacitor, with a series resistor feeding it, (from the resistance of the gates comrising the multiplexer etc..). The capacitor takes time to charge. On the 16F877A, the capacitor is 120pF, with the internal resistances being typically about 6KR for 5v operation. The pin also draws some leakage current, which is why they also specify that the source impedance feeding it, should not be above 10KR. With a 10K source impedance (the worst case allowed), the time taken for the capacitor to charge to within 0.5 bit of the 'real' voltage, over the worst value change (from a signal at the low end of the Vref, to a signal at the high end, or vice versa), is 19.72uSec. Working slightly over this (20 to 25uSec), is reasonable, going much longer, just wastes time...
It is documented in the data sheets. A lot of newer chips have smaller capacitances, and allow shorter times to be used.

Best Wishes
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