View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Cant get ADC to read anything. |
Posted: Fri Dec 19, 2003 9:42 pm |
|
|
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
|
|
Posted: Fri Dec 19, 2003 10:17 pm |
|
|
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. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Sat Dec 20, 2003 1:00 am |
|
|
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. |
|
|
|