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

multy_Input_PIC

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



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multy_Input_PIC
PostPosted: Sat Jan 20, 2007 1:11 pm     Reply with quote

I write a code for a pic which has 3 inout to convert from analog to digital .
For every channel a write the function for use the converter as show bwllow.I don't know how to call all this fucntions in main because i want to call the first channell,then disable the first channel and call the second ,disable the first and second channel and call the third channel and then go on to the first.My code is shown bellow and if anyone know the solution please tell me.




void enable_ad0(){setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(0);



}


void enable_ad1(){
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(1);
}


void enable_ad2(){
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(2);
}



void main()
{
long adc_result;

enable_ad0();
enable_ad1();
enable_ad2();
adc_result=read_adc();

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 20, 2007 1:44 pm     Reply with quote

You have the belief that every A/D channel has its own A/D converter.
That's not true. There is only one A/D converter in the PIC. There is a
channel selector circuit inside the PIC. It just connects the desired pin
to the A/D converter. You have to read each channel one at a time.

First you have to setup the A/D parameters. Then to read a channel,
you have to do this:
1. Set the channel.
2. Wait for a short delay.
3. Read the A/D result.
Then you can do the same procedure (items 1, 2, 3) for the next channel.

See my post at the end of this thread.
http://www.ccsinfo.com/forum/viewtopic.php?t=29074

You may not need the ADFM bit code, and the setup parameters may
be different for your version of the compiler and the PIC, but the basic
method of reading two or more channels is shown in that post.
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