|
|
View previous topic :: View next topic |
Author |
Message |
anjan Guest
|
16f877 adc problem |
Posted: Wed Feb 04, 2009 1:01 am |
|
|
I am using 16f877 for measuring voltage. It measures accurate voltage, but when I vary voltage, display does not show the voltage instantly, it shows voltage changing in steps. Here is the code.
Pls help.
Code: |
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <flexlcd.c>
[color=green]
void main() {
char k;
int current_temp, max_temp, min_temp,value;
int16 current_ccp_delta;
int16 frequency; int count_inc=0;
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_DIV_32);
set_adc_channel( 1 );
lcd_init();
lcd_putc("\fReady...\n");
delay_ms(500);
while (TRUE)
{
set_adc_channel( 3 );
delay_ms(10);
value = Read_ADC();
current_temp=value;
value=0;
delay_ms(20);
set_adc_channel( 1 );
delay_ms(10);
value = Read_ADC();
min_temp=value;
value=0;
delay_ms(20);
set_adc_channel( 0 );
delay_ms(10);
value = Read_ADC();
max_temp=value*2;
value=0;
printf(lcd_putc,"\fCu: %U F\nMin: %U Max:%U", current_temp,min_temp,max_temp);
delay_ms(20);
}
}[/color] |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 2:10 am |
|
|
Try a more simple program. See if this one works:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
This assumes you have a 5K trimpot connected to the AN0 input pin
(A/D channel 0). A voltage between 0v and 5v can be applied
to pin AN0 by turning the trimpot screw (or knob).
The program in the link was tested with a 4 MHz crystal, so it uses an
ADC divisor of 8. You're using a 20 MHz crystal, so you need to modify
the #use delay() statement to fit that, and also change the ADC divisor
to 32. (ie. make those two things be the same as in your posted code). |
|
|
anjan Guest
|
16f877 adc problem1 |
Posted: Wed Feb 04, 2009 4:33 am |
|
|
Dear Mr PCM,
My program measurement is Ok, But it update voltage very slowly, suppose there is a change of voltage from 4.0 to 2.6 or say 5.7, It first display 3.9,3.7 ...... then it reaches to 2.6 after sometime.like capacitor charging and discharging.
I need instant change of parameters.
I think You have understand my problem
Waiting for ur reply |
|
|
Ttelmah Guest
|
|
Posted: Wed Feb 04, 2009 5:58 am |
|
|
How are you actually feeding the voltage to the chip?. What does the voltage derive from?
Provided your source mets the impedance spec for the PIC ADC input (<10KR on the chip you are using), the PIC will happily change from one extreme of the detected voltage range to the other, in just one reading time. If your signal is not changing like this, look at the circuitry you have to generate/drive the voltage.
Best Wishes |
|
|
psypersky
Joined: 06 Jul 2008 Posts: 13
|
|
Posted: Thu Feb 26, 2009 3:03 pm |
|
|
Use Read_ADC(ADC_READ_ONLY) instead of Read_ADC(), |
|
|
|
|
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
|