Analyzer
Full Member level 6
ADC Problem with 16F877A
Hi,
I'm in trouble with adc function of 16F877A.I am using port A0,A1,A5,E0,E1,E2.When i measure voltage between ports and GND they are usually at 1 milivolt or 2 milivolts.But when i log them adc function returns 100-120 values equals to 2.0V - 2.5V.When i measure E2 it gives 50 milivolt when i dont apply voltage on it(when idle i mean)!! My device does not work properly now please help!!
My code has written with ccs c compiler v3.155
My code :
#include <16F877A.h>
#device adc=8
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main() {
int v1,v2,v3,v4,v5,v6;
char ON;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;
printf("3A75D5FA\r\n");
while (1)
{
delay_ms(500);
set_adc_channel( 0 );delay_us(100);v1 = read_adc();delay_us(100);
set_adc_channel( 1 );delay_us(100);v2 = read_adc();delay_us(100);
set_adc_channel( 4 );delay_us(100);v3 = read_adc();delay_us(100);
set_adc_channel( 5 );delay_us(100);v4 = read_adc();delay_us(100);
set_adc_channel( 6 );delay_us(100);v5 = read_adc();delay_us(100);
set_adc_channel( 7 );delay_us(100);v6 = read_adc();delay_us(100);
printf("Value:%2X/%2X/%2X/%2X/%2X/%2X!",v1,v2,v3,v4,v5,v6);
if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
}
}
I uploaded schematic if you want to look at.
Analyzer.
Hi,
I'm in trouble with adc function of 16F877A.I am using port A0,A1,A5,E0,E1,E2.When i measure voltage between ports and GND they are usually at 1 milivolt or 2 milivolts.But when i log them adc function returns 100-120 values equals to 2.0V - 2.5V.When i measure E2 it gives 50 milivolt when i dont apply voltage on it(when idle i mean)!! My device does not work properly now please help!!
My code has written with ccs c compiler v3.155
My code :
#include <16F877A.h>
#device adc=8
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main() {
int v1,v2,v3,v4,v5,v6;
char ON;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;
printf("3A75D5FA\r\n");
while (1)
{
delay_ms(500);
set_adc_channel( 0 );delay_us(100);v1 = read_adc();delay_us(100);
set_adc_channel( 1 );delay_us(100);v2 = read_adc();delay_us(100);
set_adc_channel( 4 );delay_us(100);v3 = read_adc();delay_us(100);
set_adc_channel( 5 );delay_us(100);v4 = read_adc();delay_us(100);
set_adc_channel( 6 );delay_us(100);v5 = read_adc();delay_us(100);
set_adc_channel( 7 );delay_us(100);v6 = read_adc();delay_us(100);
printf("Value:%2X/%2X/%2X/%2X/%2X/%2X!",v1,v2,v3,v4,v5,v6);
if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
}
}
I uploaded schematic if you want to look at.
Analyzer.