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

multi A/D readings

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



Joined: 12 Mar 2010
Posts: 2

View user's profile Send private message

multi A/D readings
PostPosted: Fri Mar 12, 2010 12:04 pm     Reply with quote

Hello,
I am very new to PIC microcontroller and very little knowledge.
I am trying to read 2 analog sources (potentiometer and proximity sensor) and convert them to digital values.
All the samples I found are reading from one source.
Could someone point me to the right direction and help me understand how it works.

For example: (say I want to read from A0 and A1 inputs, how do I get two readings?)
Code:
setup_adc(ALL_ANALOG); //sets porta toall analog inputs
set_adc_channel(1); //points a/d at channel 1
delay_ms(5000); //waits 5 seconds
value = read_adc(); //reads value

Thanks in advance,
Kevin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 12, 2010 12:17 pm     Reply with quote

Set the channel. Wait for a short delay (not 5 seconds). Then read
the A/D value into a variable. Example:
Code:

set_adc_channel(0);
delay_us(20);
result_0 = read_adc();

set_adc_channel(1);
delay_us(20);
result_1 = read_adc();
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