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

ADC Help Please

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







ADC Help Please
PostPosted: Sat Dec 23, 2006 5:02 pm     Reply with quote

Hi I am very new at PIC programming and am becoming very frustrated.

Can anyone help me set up an Analog to Digital Conversion? I have a Picdem 2 Plus demo board and would like to program the POT on RA0 to read the input and output the value in a digital fashion.

I have set #device ADC=10 in the C file just after #include<16F877A.h>
#use standard_io(D)
int 16 a, b, c, d, e;
int 16 value;

VOID MAIN(VOID){
delay_ms(200);
tris_portd = 0x00;
SETUP_ADC_PORTS(RA0_ANALOG);
SETUP_ADC(ADC_CLOCK_DIV_32);

WHILE(1){
a = 205;
b = 410;
c = 615;
d = 820;
e = 1024;
set_adc_channel(0);
delay_us(20);
value = READ_ADC();
..........

Then there are several IF statements so that LEDs can be lit up accordingly. Obviously alot of code is missing but I tried to include only the important ADC portions of the code. If anyone can tell me where I am going wrong or what I am missing I would sure be thankfull.

Thanks again, Abe
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Dec 23, 2006 5:32 pm     Reply with quote

I don't see an obvious error in your program. You didn't give a complete program, neither did you tell us what isn't working so right now we can't help you any further.
Give us a small but complete program to test (and then please use the 'code' buttons for preserving the code layout).
Or you might have give the program ex_admm.c in the picc/example directory a try to see if that is working.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 23, 2006 6:36 pm     Reply with quote

Quote:

I have a Picdem 2 Plus demo board and would like to program the POT
on RA0 to read the input and output the value in a digital fashion.

Read my post near the end of the following thread. You'll find sample
code to use the ADC with the trimpot on the PicDem2-Plus board:
http://www.ccsinfo.com/forum/viewtopic.php?t=28842
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