|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
ADC Problem still continues |
Posted: Wed Jun 04, 2003 4:34 am |
|
|
<font face="Courier New" size=-1>Hi,
I'm still 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!!
No_Fear
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 upload schematic at www.mcu.cz/atm
Follow Home->Schematics->877.gif
Please Helpp!!</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515026 |
|
|
Tomi Guest
|
Re: ADC Problem still continues |
Posted: Wed Jun 04, 2003 8:31 am |
|
|
Do you have any analog voltage on any input pin?
Don't forget that the PIC has only one A/D converter. The analog inputs are multiplexed. After the multiplexer there is a S/H circuit. Let's say the capac. in the S/H is charged to e.g. 2V (from a previously measured analog pin or from an internal circuit like itself the S/H). In this case because the selected analog pin is floating you will measure something proportional with the previous measurement.
Typically, if you have 8 analog inputs and the first is connected to 2.5V and the others are floating, you will get something like this (AD0-7, 8bit mode): 128,100,80,70,60,50,45,42 (the S/H capacitance discharges exponentially).
I always use a big pulldown resistor (e.g. 100k) on analog inputs not only for set the undriven inputs into a definite state but to give chance to S/H circuit to discharge the capacitor over these resistors.
:=I'm still 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!!
:=
:=No_Fear
:=
:=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 upload schematic at www.mcu.cz/atm
:=Follow Home->Schematics->877.gif
:=
:=
:=Please Helpp!!</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515029 |
|
|
No_Fear Guest
|
Re: ADC Problem still continues |
Posted: Wed Jun 04, 2003 4:16 pm |
|
|
Hi,
I fixed my problem.I remove 100 ohms resistors and zenner diodes and i connect 100 nf cap between gnd and every analog ch.An i connect 2.2 Kohms res. parallelly to capacitors.Now it works well.Thank you.
No_Fear
:=Do you have any analog voltage on any input pin?
:=Don't forget that the PIC has only one A/D converter. The analog inputs are multiplexed. After the multiplexer there is a S/H circuit. Let's say the capac. in the S/H is charged to e.g. 2V (from a previously measured analog pin or from an internal circuit like itself <img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0"> the S/H). In this case because the selected analog pin is floating you will measure something proportional with the previous measurement.
:=Typically, if you have 8 analog inputs and the first is connected to 2.5V and the others are floating, you will get something like this (AD0-7, 8bit mode): 128,100,80,70,60,50,45,42 (the S/H capacitance discharges exponentially).
:=I always use a big pulldown resistor (e.g. 100k) on analog inputs not only for set the undriven inputs into a definite state but to give chance to S/H circuit to discharge the capacitor over these resistors.
:=
:=:=I'm still 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!!
:=:=
:=:=No_Fear
:=:=
:=:=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 upload schematic at www.mcu.cz/atm
:=:=Follow Home->Schematics->877.gif
:=:=
:=:=
:=:=Please Helpp!!</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515040 |
|
|
|
|
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
|