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

help with a/d

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



Joined: 17 Sep 2005
Posts: 1

View user's profile Send private message Send e-mail

help with a/d
PostPosted: Sat Sep 17, 2005 11:33 am     Reply with quote

Hello,
I am a volunteering in my school's lab. I am programming a project to control some motors.

To get myself aquainted to a PIC and its internal a/d converter I wrote this simple program. However, I cannot seem to get it to operate correctly. All I am having it do is output high until it receives a certain input on the a/d. Any suggestions?

#include <16F873.h>
#device adc=8
#use delay(clock=4000000)
#fuses XT, PUT, NOWDT, NOPROTECT, NOLVP

void main()
{
int input;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(FALSE);
setup_counters(RTCC_EXT_L_TO_H,WDT_18MS);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);

input = 0;

output_high(PIN_B0);

while(1)
{
delay_ms(500);
input = read_adc();
if(input >= 20)
{
output_low(PIN_B0);
}

}
}
_________________
hi, im new
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 17, 2005 12:10 pm     Reply with quote

You need to select the A/D channel that you're using. Set it up to
use the channel that you have your trimpot connected to. Example:

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
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