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

Cant get ADC to read anything.

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



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

Cant get ADC to read anything.
PostPosted: Fri Dec 19, 2003 9:42 pm     Reply with quote

Like the subject says, the I dont think value is ever anything other then 0. I'm guessing somthing is wrong on the code end, but it looks very close to other code I've searched.

It supposed to turn a led on/off when it sees 1.850V (I used a dmm on the pin, there IS exactly 1.850 coming in (I gave it some room in the code though)

Code:

#include <16F872.h>
#device ADC=10
#fuses RC,LVP,NOWDT,NOPROTECT, PUT, NOBROWNOUT
#use delay(clock=1000000)

int led=FALSE;
long value=0;

void changeLED() {
 if (led) {
  led=FALSE;
  output_low(PIN_B6);
 }
 else {
  led=TRUE;
  output_high(PIN_B6);
 }
}


void main() {

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
set_adc_channel(0);
delay_us(20);

led=0;
value=0;
output_high(PIN_C0); //Cruise 4.94V Lead +- .02V

 while(1) {

  value = read_adc();
  delay_us(20);

  if ((value > 365) && (value < 399))   //1.850V / 5V =0x= 17A +- alot   changeLED();

  if (value != 0)
   output_high(PIN_C6);   



  delay_ms(250);
 } //eow
} //eom


If I hook A0 to 5V, C6 still doesnt output....

Ideas?
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Fri Dec 19, 2003 10:17 pm     Reply with quote

Solved.

For some reason I had #Device ADC=10 in my post but not in my code, I put that in and it worked... very odd.

I would have figured ADC=X would have been set to somthing by default for whatever chip is being used.

Guess Not. Laughing
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sat Dec 20, 2003 1:00 am     Reply with quote

It is working now, but you might wanna take a look at the datasheet to see what the recommended ADC clock setting is for a 10MHz crystal.
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